Discord.SortedSet.NifBridge (SortedSet v2.0.1) View Source

Discord.SortedSet.NifBridge is an internal implementation detail of the NIF backed Discord.SortedSet.

This module exists to provide a clean separation between the FFI and API exposed to the end user, see the Discord.SortedSet module for the public API.

There may be advanced use cases that find it useful to use the Discord.SortedSet.NifBridge directly, but for most use-cases the Discord.SortedSet module provides a more conventional interface.

Link to this section Summary

Functions

Adds an item to the SortedSet.

Appends a buckets worth of sorted terms to the SortedSet

Retrieve the item at the specified index

Returns a string representation of the underlying Rust data structure.

Creates an empty SortedSet.

Finds the index of the specified item

Creates a new SortedSet.

Removes an item from the SortedSet.

Gets the size of the SortedSet.

Retrieve a slice of starting at the start index and taking up to amount

Converts a SortedSet into a standard list

Link to this section Types

Link to this type

jemalloc_allocation_data()

View Source

Specs

jemalloc_allocation_data() :: %{
  epoch: integer(),
  active: integer(),
  allocated: integer(),
  mapped: integer(),
  metadata: integer(),
  resident: integer(),
  retained: integer()
}

Link to this section Functions

Specs

Adds an item to the SortedSet.

Link to this function

append_bucket(set, terms)

View Source

Specs

Appends a buckets worth of sorted terms to the SortedSet

This is mostly an internal implementation detail, it is used to implement the Discord.SortedSet.from_enumerable/2 and Discord.SortedSet.from_proper_enumerable/2 functions. The NIF will append a buckets worth of items without performing any checks on them. This is a very efficient way to build the SortedSet but care must be taken since the call circumvents the sorting and sanity checking logic. Use the constructors in Discord.ßSortedSet for a safer and more ergonomic experience, use great care when calling this function directly.

Specs

Retrieve the item at the specified index

Specs

Returns a string representation of the underlying Rust data structure.

This function is mostly provided as a convenience, since the actual data structure is stored in the NIF memory space it can be difficult to introspect the data structure as it changes. This function allows the caller to get the view of the data structure as Rust sees it.

Link to this function

empty(capacity, bucket_size)

View Source

Specs

empty(capacity :: pos_integer(), bucket_size :: pos_integer()) ::
  {:ok, Discord.SortedSet.t()}

Creates an empty SortedSet.

This is mostly an internal implementation detail, it is used to implement the Discord.SortedSet.from_enumerable/2 and Discord.SortedSet.from_proper_enumerable/2 functions. The only valid operation that can be performed on an empty Discord.SortedSet is append_bucket/2, all other functions expect that the bucket not be completely empty.

Specs

Finds the index of the specified item

Link to this function

jemalloc_allocation_info()

View Source

Specs

jemalloc_allocation_info() ::
  {:ok, jemalloc_allocation_data()} | {:error, any()}
Link to this function

new(capacity, bucket_size)

View Source

Specs

new(capacity :: pos_integer(), bucket_size :: pos_integer()) ::
  {:ok, Discord.SortedSet.t()}

Creates a new SortedSet.

To prevent copying the set into and out of NIF space, the NIF returns an opaque reference handle that should be used in all subsequent calls to identify the SortedSet.

Specs

Removes an item from the SortedSet.

Specs

size(set :: Discord.SortedSet.t()) :: non_neg_integer()

Gets the size of the SortedSet.

This function follows the standard Elixir naming convention, size takes O(1) time as the size is tracked with every addition and removal.

Link to this function

slice(set, start, amount)

View Source

Specs

slice(
  set :: Discord.SortedSet.t(),
  start :: non_neg_integer(),
  amount :: non_neg_integer()
) ::
  [any()] | Discord.SortedSet.Types.common_errors()

Retrieve a slice of starting at the start index and taking up to amount

Specs

Converts a SortedSet into a standard list

Note: This is potentially an expensive operation because it must copy the NIF data back into BEAM VM space.