interfaces

  1. allocator
  2. identity
    1. comparator
    2. equality
    3. key_accessor
  3. serialization
    1. hash64
    2. pack
    3. unpack
  4. external iterators
    1. iterator
  5. internal iterators
    1. fori
    2. foreach
    3. map

The interfaces module provides a set of standard function pointer definitions. and default implementations for common operations.

allocator

An allocator function is responsible for memory management. It handles allocation, reallocation, and deallocation.

typedef void *(fn_allocator) ( void *p_pointer, unsigned long long size );

Parameters

p_pointer
pointer to allocated memory OR NULL
size
desired allocation size OR 0

Returns

  • A pointer to size bytes of memory IF p_pointer IS NULL AND size > 0
  • A pointer to size bytes of memory IF p_pointer IS NOT NULL AND size > 0
  • NULL IF size IS 0

identity

comparator

A comparator function imposes a total ordering on some collection of objects

typedef int (fn_comparator) ( const void *p_a, const void *p_b );

Parameters

p_a
pointer to A
p_b
pointer to B

Returns

  • < 0 IF A < B
  • = 0 IF A == B
  • > 0 IF A > B

equality

An equality function tests if two elements are equal.

typedef int (fn_equality) ( const void *p_a, const void *p_b );

Parameters

p_a
pointer to A
p_b
pointer to B

Returns

  • 1 IF A == B
  • 0 IF A != B

key accessor

A key accessor function extracts a key from a value.

typedef void *(fn_key_accessor) ( const void *const p_value );

Parameters

p_value
pointer to value

Returns

  • pointer to key

serialization

hash64

A hash64 function computes a 64-bit hash of a key.

typedef hash64 (fn_hash64) ( const void *const k , unsigned long long l );

Parameters

k
pointer to key
l
quantity of bytes to hash

Returns

  • pointer to key

pack

A pack function serializes a value into a stream.

typedef int (fn_pack) ( stream *p_stream, const void *const p_value );

Parameters

p_stream
pointer to stream
p_value
pointer to value

Returns

  • bytes written to stream

unpack

An unpack function deserializes a value from a stream.

typedef int (fn_unpack) ( void *p_value , stream *p_stream );

Parameters

p_value
pointer to value
p_stream
pointer to stream

Returns

  • bytes read from stream

external iterators

iterator

struct iterator_s
{
    void *p_data;
    struct 
    {
        void *p_state;
        void *p_auxiliary;
    } state;
    fn_it_done *done;
    fn_it_next *next;
    fn_it_item *item;
};
typedef bool (fn_it_done) ( iterator *p_it );
typedef void (fn_it_next) ( iterator *p_it );
typedef void *(fn_it_item) ( iterator *p_it );

internal iterators

fori

A fori function is an iterator that provides an element and its index.

typedef void (fn_fori) ( void *p_element, int i );

Parameters

p_element
the element
i
the index

Returns

  • void

foreach

A foreach function is an iterator that provides an element.

typedef void (fn_foreach) ( void *p_element );

Parameters

p_element
the element

Returns

  • void

map

A map function transforms an element.

typedef void *(fn_map) ( void *p_element );

Parameters

p_element
the element

Returns

  • void *