bravo/uset

This module provides functions to work with USets

Types

An unordered set. Keys may only occur once per table, and objects are unordered.

In order for a lookup match to occur, entries must have the same value and type.

pub opaque type USet(t)

Functions

pub fn delete(uset: USet(a)) -> Bool

Deletes a USet.

Table lifetime is static, and memory is only freed when the owner process is killed! Don’t forget to call this function!

pub fn delete_all_objects(uset: USet(a)) -> Nil

Deletes all objects in the USet. This is atomic and isolated.

pub fn delete_key(uset: USet(a), key: b) -> Nil

Deletes the object addressed by key, if it exists. If it doesn’t, this does nothing.

pub fn delete_object(uset: USet(a), object: a) -> Nil

Deletes a specific object in the USet. This is more useful in Bags and DBags.

pub fn insert(uset: USet(a), objects: List(a)) -> Bool

Inserts a list of tuples into a USet.

Returns a Bool representing if the inserting succeeded.

  • If True, all objects in the list were inserted.
  • If False, none of the objects in the list were inserted. This may occur if the size of the tuple is less than the USet’s size.

If an object with the same key already exists, then the old object will be overwritten with the new one.

pub fn lookup(uset: USet(a), key: b) -> Option(a)

Gets an object from a USet.

Returns an Option containing the object, if it exists.

pub fn new(
  name: String,
  keypos: Int,
  access: Access,
) -> Result(USet(a), Option(ErlangError))

Creates a new ETS table configured as a set: keys may only occur once per table, and objects are unordered.

name: An atom representing the name of the USet. There may only be one ETS table associated with an atom. keypos: The index (1-indexed) that represents the key position of the object. This function fails if this is less than 1. access: Determines how visible the table is to other processes.

  • Public: Any process can read or write to the USet.
  • Protected: Any process can read the USet. Only the owner process can write to it.
  • Private: Only the parent process can read or write to the USet.

Returns a result of the created USet, which can be used by other functions in this module. If this function errors with None, then you likely put in an illegal keypos value. Otherwise, something went wrong in the FFI layer and an error occured in Erlang land.

Search Document