discord/sorted_set_nif hiện có 1.6k sao trên GitHub, viết chủ yếu bằng Elixir. Elixir SortedSet backed by a Rust-based NIF
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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
Function in the Rust Programming Language, using the Rustler crate.
Installation
Add SortedSet to your dependencies and then install with mix do deps.get, deps.compile
def deps do
[
{:sorted_set_nif, "~> 1.0.0"}
]
end
Implementation Details
Internally the Elixir terms stored in the SortedSet are converted to Rust equivalents and
stored in a Vector of Vectors. The structure is similar to a skip-list, almost every operation
on the SortedSet will perform a linear scan through the buckets to find the bucket that owns the
term, then a binary search is done within the bucket to complete the operation.
Why not just a Vector of Terms? This approach was explored but when the Vector needs to grow
beyond it's capacity, copying Terms over to the new larger Vector proved to be a performance
bottle neck. Using a Vector of Vectors, the Bucket pointers can be quickly copied when
additional capacity is required.
This strategy provides a reasonable trade off between performance and implementation complexity.
When using a SortedSet, the caller can tune bucket sizes to their use case. A default bucket
size of 500 was chosen as it provides good performance for most use cases. See new/2 for
details on how to provide custom tuning details.
Guarantees
Terms in the SortedSet will be sorted based on the Elixir sorting rules.
SortedSet is a Set, any item can appear 0 or 1 times in the Set.
Functionality
There is some special functionality that SortedSet provides beyond sorted and uniqueness
guarantees.
SortedSet has a defined ordering, unlike a pure mathematical set.
SortedSet can report the index of adding and removing items from the Set due to it's defined
ordering property.
SortedSet can provide random access of items and slices due to it's defined ordering
property.
Caveats
Due to SortedSet's implementation, some operations that are constant time in sets have
different performance characteristic in SortedSet, these are noted on the operations.
SortedSets do not support some types of Elixir Terms, namely reference, pid, port,
function, and float. Attempting to store any of these types (or an allowed composite
type containing one of the disallowed types) will result in an error, namely,
{:error, :unsupported_type}
Documentation
Documentation is hosted on hexdocs.
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.
$ mix deps.get
$ 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
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
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
benchmarks.
There are benchmarks available in the bench folder, these are written with
Benchee and can be run with the following command.
$ OPTIMIZE_NIF=true mix run bench/{benchmark}.exs
Adding the OPTIMIZE_NIF=true will force the benchmark to run against the fully optimized NIF.
Basic Usage
SortedSet lives in the Discord namespace to prevent symbol collision, it can be used directly
defmodule ExampleModule do
def get_example_sorted_set() do
Discord.SortedSet.new()
|> Discord.SortedSet.add(1)
|> Discord.SortedSet.add(:atom),
|> Discord.SortedSet.add("hi there!")
end
end
You can always add an alias to make this code less verbose
defmodule ExampleModule do
alias Discord.SortedSet
def get_example_sorted_set() do
SortedSet.new()
|> SortedSet.add(1)
|> SortedSet.add(:atom),
|> SortedSet.add("hi there!")
end
end
Full API Documentation is available, there is also a full test suite with examples of how the
library can be used.
discord/sorted_set_nif có 1.6k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/discord/sorted_set_nif. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
discord/sorted_set_nif có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho discord/sorted_set_nif. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
discord/sorted_set_nif còn đang phát triển không?
Commit gần nhất trên discord/sorted_set_nif là 3 tháng trước (theo timestamp GitHub). Repo có 101 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
discord/sorted_set_nif viết bằng ngôn ngữ gì?
discord/sorted_set_nif chủ yếu viết bằng Elixir. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về discord/sorted_set_nif ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/discord/sorted_set_nif là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về sorted_set_nif?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về sorted_set_nif.