Module ec_dictionary

A module that supports association of keys to values.

Copyright © 2011 Erlware, LLC.

This module defines the ec_dictionary behaviour.
Required callback functions: new/0, has_key/2, get/2, add/3, remove/2, has_value/2, size/1, to_list/1, from_list/1, keys/1.

Authors: Eric Merritt (ericbmerritt@gmail.com).

Description

A module that supports association of keys to values. A map cannot contain duplicate keys; each key can map to at most one value.

This interface is a member of the Erlware Commons Library.

Data Types

dictionary()

dictionary(_K, _V) = #dict_t{}

key()

key(T) = T

value()

value(T) = T

Function Index

add/3add a new value to the existing dictionary.
behaviour_info/1
from_list/2Create a new dictionary, of the specified implementation using the list provided as the starting contents.
get/2given a key return that key from the dictionary.
get/3given a key return that key from the dictionary.
has_key/2check to see if the dictionary provided has the specified key.
has_value/2Check to see if the value exists in the dictionary.
keys/1Return the keys of this dictionary as a list.
new/1create a new dictionary object from the specified module.
remove/2Remove a value from the dictionary returning a new dictionary with the value removed.
size/1return the current number of key value pairs in the dictionary.
to_list/1Return the contents of this dictionary as a list of key value pairs.

Function Details

add/3

add(Key::key(K), Value::value(V), Dict_t::dictionary(K, V)) -> dictionary(K, V)

Key: the key to add
Value: the value to add

add a new value to the existing dictionary. Return a new dictionary containing the value.

behaviour_info/1

behaviour_info(Other::atom()) -> [{atom(), arity()}] | undefined

from_list/2

from_list(ModuleName::module(), List::[{key(K), value(V)}]) -> dictionary(K, V)

ModuleName: the type to create the dictionary from
List: The list of key value pairs to start with

Create a new dictionary, of the specified implementation using the list provided as the starting contents.

get/2

get(Key::key(K), Dict_t::dictionary(K, V)) -> value(V)

Key: The key requested when the key does not exist @throws not_found

given a key return that key from the dictionary. If the key is not found throw a 'not_found' exception.

get/3

get(Key::key(K), Default::value(V), Dict_t::dictionary(K, V)) -> value(V)

Key: The key requested
Default: The value that will be returned if no value is found in the database.

given a key return that key from the dictionary. If the key is not found then the default value is returned.

has_key/2

has_key(Key::key(K), Dict_t::dictionary(K, _V)) -> boolean()

Key: The key to check the dictionary for

check to see if the dictionary provided has the specified key.

has_value/2

has_value(Value::value(V), Dict_t::dictionary(_K, V)) -> boolean()

Value: The value to check if exists

Check to see if the value exists in the dictionary

keys/1

keys(Dict::dictionary(K, _V)) -> [key(K)]

Dict: the base dictionary to make use of.

Return the keys of this dictionary as a list

new/1

new(ModuleName::module()) -> dictionary(_K, _V)

ModuleName: The module name.

create a new dictionary object from the specified module. The module should implement the dictionary behaviour.

remove/2

remove(Key::key(K), Dict_t::dictionary(K, V)) -> dictionary(K, V)

Key: the key of the key/value pair to remove

Remove a value from the dictionary returning a new dictionary with the value removed.

size/1

size(Dict_t::dictionary(_K, _V)) -> integer()

return the current number of key value pairs in the dictionary

to_list/1

to_list(Dict::dictionary(K, V)) -> [{key(K), value(V)}]

Dict: the base dictionary to make use of.

Return the contents of this dictionary as a list of key value pairs.


Generated by EDoc, Feb 15 2022, 15:17:47.