Project Lucy has retired. For details please refer to its Attic page.
Clownfish::Hash – C API Documentation
Apache Lucy™

Clownfish::Hash

parcel Clownfish
class variable CFISH_HASH
struct symbol cfish_Hash
class nickname cfish_Hash
header file Clownfish/Hash.h

Name

Clownfish::Hash – Hashtable.

Description

Values are stored by reference and may be any kind of Obj.

Functions

new
cfish_Hash* // incremented
cfish_Hash_new(
    size_t capacity
);

Return a new Hash.

capacity

The number of elements that the hash will be asked to hold initially.

init
cfish_Hash*
cfish_Hash_init(
    cfish_Hash *self,
    size_t capacity
);

Initialize a Hash.

capacity

The number of elements that the hash will be asked to hold initially.

Methods

Clear
void
cfish_Hash_Clear(
    cfish_Hash *self
);

Empty the hash of all key-value pairs.

Store
void
cfish_Hash_Store(
    cfish_Hash *self,
    cfish_String *key,
    cfish_Obj *value // decremented
);

Store a key-value pair.

Store_Utf8
void
cfish_Hash_Store_Utf8(
    cfish_Hash *self,
    char *utf8,
    size_t size,
    cfish_Obj *value // decremented
);

Store a key-value pair using a raw UTF-8 key.

utf8

Pointer to UTF-8 character data of the key.

size

Size of UTF-8 character data in bytes.

value

The Obj to store.

Fetch
cfish_Obj*
cfish_Hash_Fetch(
    cfish_Hash *self,
    cfish_String *key
);

Fetch the value associated with key.

Returns: the value, or NULL if key is not present.

Fetch_Utf8
cfish_Obj*
cfish_Hash_Fetch_Utf8(
    cfish_Hash *self,
    char *utf8,
    size_t size
);

Fetch the value associated with a raw UTF-8 key.

utf8

Pointer to UTF-8 character data of the key.

size

Size of UTF-8 character data in bytes.

Returns: the value, or NULL if key is not present.

Delete
cfish_Obj* // incremented
cfish_Hash_Delete(
    cfish_Hash *self,
    cfish_String *key
);

Attempt to delete a key-value pair from the hash.

Returns: the value if key exists and thus deletion succeeds; otherwise NULL.

Delete_Utf8
cfish_Obj* // incremented
cfish_Hash_Delete_Utf8(
    cfish_Hash *self,
    char *utf8,
    size_t size
);

Attempt to delete a key-value pair from the hash.

utf8

Pointer to UTF-8 character data of the key.

size

Size of UTF-8 character data in bytes.

Returns: the value if key exists and thus deletion succeeds; otherwise NULL.

Has_Key
bool
cfish_Hash_Has_Key(
    cfish_Hash *self,
    cfish_String *key
);

Indicate whether the supplied key is present.

Keys
cfish_Vector* // incremented
cfish_Hash_Keys(
    cfish_Hash *self
);

Return the Hash’s keys.

Values
cfish_Vector* // incremented
cfish_Hash_Values(
    cfish_Hash *self
);

Return the Hash’s values.

Get_Size
size_t
cfish_Hash_Get_Size(
    cfish_Hash *self
);

Return the number of key-value pairs.

Equals
bool
cfish_Hash_Equals(
    cfish_Hash *self,
    cfish_Obj *other
);

Equality test.

Returns: true if other is a Hash with the same key-value pairs as self. Keys and values are compared using their respective Equals methods.

Inheritance

Clownfish::Hash is a Clownfish::Obj.