Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- "*"

jobs:
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-elixir@v1
with:
otp-version: '24.0'
elixir-version: 1.12.2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: ./native/sorted_set_nif

format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
override: true
- uses: erlef/setup-elixir@v1
with:
otp-version: '24.0'
elixir-version: 1.12.2
- run: cargo fmt --all -- --check
working-directory: ./native/sorted_set_nif
- run: mix format --check-formatted

test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
rust-version:
- stable
- nightly
- nightly-2021-01-25
beam-pair:
- otp-version: '21.3'
elixir-version: 1.7.4
- otp-version: '23.3'
elixir-version: 1.11.4
- otp-version: '24.0'
elixir-version: 1.12.2
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust-version }}
components: clippy, rustfmt
- uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.beam-pair.elixir-version }}
otp-version: ${{ matrix.beam-pair.otp-version }}
- run: cargo test
working-directory: ./native/sorted_set_nif
- run: mix deps.get
- run: mix compile
- run: mix test
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Discord.SortedSet

[![CI](https://github.com/discord/sorted_set_nif/workflows/CI/badge.svg)](https://github.com/discord/sorted_set_nif/actions)
[![Hex.pm Version](http://img.shields.io/hexpm/v/sorted_set_nif.svg?style=flat)](https://hex.pm/packages/sorted_set_nif)
[![CI](https://github.com/discord/sorted_set_nif/workflows/CI/badge.svg)](https://github.com/discord/sorted_set_nif/actions)

SortedSet is a fast and efficient data structure that provides certain guarantees and
functionality. The core data structure and algorithms are implemented in a Native Implemented
Expand Down Expand Up @@ -65,7 +67,7 @@ guarantees.

Documentation is [hosted on hexdocs](https://hexdocs.pm/sorted_set_nif).

For a local copy of the documentation, the `mix.exs` file is already set up for generating
For a local copy of the documentation, the `mix.exs` file is already set up for generating
documentation, simply run the following commands to generate the documentation from source.

```bash
Expand All @@ -75,20 +77,20 @@ $ mix docs

## Running the Tests

There are two test suites available in this library, an ExUnit test suite that tests the
correctness of the implementation from a black box point of view. These tests can be run by
There are two test suites available in this library, an ExUnit test suite that tests the
correctness of the implementation from a black box point of view. These tests can be run by
running `mix test` in the root of the library.

The rust code also contains tests, these can be run by running `cargo test` in the
The rust code also contains tests, these can be run by running `cargo test` in the
`native/sorted_set_nif` directory.

## Running the Benchmarks

Before running any benchmarks it's important to remember that during development the NIF will be
built unoptimized. Make sure to rebuild an optimized version of the NIF before running the
Before running any benchmarks it's important to remember that during development the NIF will be
built unoptimized. Make sure to rebuild an optimized version of the NIF before running the
benchmarks.

There are benchmarks available in the `bench` folder, these are written with
There are benchmarks available in the `bench` folder, these are written with
[Benchee](https://github.com/PragTob/benchee) and can be run with the following command.

```bash
Expand All @@ -99,7 +101,7 @@ Adding the `OPTIMIZE_NIF=true` will force the benchmark to run against the fully

## Basic Usage

SortedSet lives in the `Discord` namespace to prevent symbol collision, it can be used directly
SortedSet lives in the `Discord` namespace to prevent symbol collision, it can be used directly

```elixir
defmodule ExampleModule do
Expand All @@ -117,7 +119,7 @@ You can always add an `alias` to make this code less verbose
```elixir
defmodule ExampleModule do
alias Discord.SortedSet

def get_example_sorted_set() do
SortedSet.new()
|> SortedSet.add(1)
Expand All @@ -127,5 +129,5 @@ defmodule ExampleModule do
end
```

Full API Documentation is available, there is also a full test suite with examples of how the
library can be used.
Full API Documentation is available, there is also a full test suite with examples of how the
library can be used.
1 change: 0 additions & 1 deletion native/sorted_set_nif/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ impl Bucket {
mod tests {
use super::*;
use std::cmp::Ordering;
use AddResult;

#[test]
fn test_item_compare_empty_bucket() {
Expand Down
28 changes: 8 additions & 20 deletions native/sorted_set_nif/src/sorted_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ mod tests {
let item = Bitstring(String::from("test-item"));
match set.add(item) {
Added(idx) => assert_eq!(idx, 0),
Duplicate(idx) => panic!(format!("Unexpected Duplicate({}) on initial add", idx)),
Duplicate(idx) => panic!("Unexpected Duplicate({}) on initial add", idx),
};
assert_eq!(set.size(), 1);

let item = Bitstring(String::from("test-item"));
match set.add(item) {
Added(idx) => panic!(format!("Unexpected Added({}) on subsequent add", idx)),
Added(idx) => panic!("Unexpected Added({}) on subsequent add", idx),
Duplicate(idx) => assert_eq!(idx, 0),
}
assert_eq!(set.size(), 1);
Expand All @@ -295,13 +295,7 @@ mod tests {
assert_eq!(*set.at(1).unwrap(), Bitstring(String::from("bbb")));
assert_eq!(*set.at(2).unwrap(), Bitstring(String::from("ccc")));

match set.at(3) {
Some(item) => panic!(format!(
"Unexpected item found after end of set: {:?}",
item
)),
None => assert!(true),
};
assert_eq!(set.at(3), None);
}

#[test]
Expand All @@ -325,10 +319,10 @@ mod tests {

match set.remove(&item) {
Removed(idx) => assert_eq!(idx, 1),
NotFound => panic!(format!(
NotFound => panic!(
"Unexpected NotFound for item that should be present: {:?}",
item
)),
),
}

assert_eq!(
Expand Down Expand Up @@ -359,13 +353,7 @@ mod tests {

let item = Bitstring(String::from("zzz"));

match set.remove(&item) {
Removed(idx) => panic!(
"Unexpected Removed({}) for item that should not be present",
idx
),
NotFound => assert!(true),
}
assert_eq!(set.remove(&item), NotFound);

assert_eq!(
set.to_vec(),
Expand Down Expand Up @@ -405,10 +393,10 @@ mod tests {

match set.remove(&item) {
Removed(idx) => assert_eq!(idx, 3),
NotFound => panic!(format!(
NotFound => panic!(
"Unexpected NotFound for item that should be present: {:?}",
item
)),
),
}

assert_eq!(
Expand Down