bravo/dbag
This module provides functions to work with DBag
s
Types
Functions
pub fn delete(dbag: DBag) -> Bool
Deletes a DBag
.
Table lifetime is static, and memory is only freed when the owner process is killed! Don’t forget to call this function!
pub fn insert(dbag: DBag, objects: List(a)) -> Bool
Inserts a list of tuples into a DBag
.
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 theDBag
’s size.
If an Object
with the same key already exists, then the old Object
will be overwritten with the new one.
pub fn insert_obj(dbag: DBag, objects: List(Object(a))) -> Bool
Inserts a list of Object
s into a DBag
. It is recommended to use insert
instead when possible, as this uses that function under the hood.
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 theDBag
’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(dbag: DBag, key: a) -> List(Object(Dynamic))
Gets an Object
from a DBag
.
Returns an Option
containing the object, if it exists.
- If
Some
, then the object was found. ETS tables do not store types, so you must decode aDynamic
inside theObject
. - If
None
, then theDBag
did not contain anyObject
with the specifiedkey
.
pub fn new(
name: String,
keypos: Int,
access: Access,
) -> Result(DBag, Option(ErlangError))
Creates a new ETS table configured as a duplicate bag: keys may occur multiple times per table, and verbatim copies of an object can be stored.
name
: An atom representing the name of the DBag
. 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 theDBag
.Protected
: Any process can read theDBag
. Only the owner process can write to it.Private
: Only the parent process can read or write to theDBag
.
Returns a result of the created DBag
, 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.