Skip to content

API Reference

Namespaces

Name Description
test

Classes

Name Description
Item The Item struct, contains a value of any kind, and a function to free the value and print the value.
List The List struct, contains a header for size, capacity, and resizing multiple and then a List of Items.
HashMap The HashMap struct, contains a header for size, capacity, and resizing multiple. Has a list of entries and a pointer to a hashing function.
LinkedList
HashMapItem The HashMapItem struct. Contains the key, the value, and a next field for collisions.
ComplexHashMap
LinkedListNode
ItemValueOperations

Macros


ITEM_TYPES_MATCH

#define ITEM_TYPES_MATCH(item1, item2) ((item1)->type_id == (item2)->type_id)

Typedefs


ItemValueFreeFunction

using ItemValueFreeFunction = void

A function that will be a part of the Item struct, it determines how the Item will be freed.


ItemValuePrintFunction

using ItemValuePrintFunction = void

A function that will be a part of the Item struct, it determines how the Item will be printed, mainly for debugging.


ItemValueToStringFunction

using ItemValueToStringFunction = char *

A function that will be a part of the Item struct, it determines how the Item can be converted to a string.


ItemValueReplicateFunction

using ItemValueReplicateFunction = void *

ItemValueEquivalenceFunction

using ItemValueEquivalenceFunction = bool

ItemValueHashFunction

using ItemValueHashFunction = u_int32_t

HashFunction

using HashFunction = u_int32_t

A Function that takes key and a capacity and hashes the key to return an index.


ComplexHashMapItem

using ComplexHashMapItem = struct complexHashMapItem

Functions


ListFree

void ListFree(void * list)

Frees the List and all the Items in the List.

Parameters

Parameter Type Description
list void * The List to free.

HashMapFree

void HashMapFree(void * map)

Frees a HashMap.

Parameters

Parameter Type Description
map void * The HashMap that should be freed.

DefaultPrint

void DefaultPrint(void * v)

PrintString

void PrintString(void * value)

PrintInt

void PrintInt(void * value)

ListPrint

void ListPrint(void * list)

HashMapPrint

void HashMapPrint(void * map)

LinkedListPrint

void LinkedListPrint(void * list)

ComplexHashMapPrint

void ComplexHashMapPrint(void * map)

DefaultToString

char * DefaultToString(void * v)

StringToString

char * StringToString(void * s)

IntToString

char * IntToString(void * num)

ListToString

char * ListToString(void * list)

HashMapToString

char * HashMapToString(void * map)

LinkedListToString

char * LinkedListToString(void * list)

ComplexHashMapToString

char * ComplexHashMapToString(void * map)

DefaultDuplicate

void * DefaultDuplicate(void * v)

DuplicateInt

void * DuplicateInt(void * original)

DuplicateString

void * DuplicateString(void * original)

ListDuplicate

void * ListDuplicate(void * list)

HashMapDuplicate

void * HashMapDuplicate(void * map)

LinkedListDuplicate

void * LinkedListDuplicate(void * list)

StringEquivalence

bool StringEquivalence(void * s1, void * s2)

IntEquivalence

bool IntEquivalence(void * int1, void * int2)

ListEquivalence

bool ListEquivalence(void * list1, void * list2)

HashMapEquivalence

bool HashMapEquivalence(void * map1, void * map2)

ComplexHashMapEquivalence

bool ComplexHashMapEquivalence(void * map1, void * map2)

StringHash

u_int32_t StringHash(void * str)

IntHash

u_int32_t IntHash(void * integer)

ListHash

u_int32_t ListHash(void * list)

HashMapHash

u_int32_t HashMapHash(void * map)

ComplexHashMapHash

u_int32_t ComplexHashMapHash(void * map)

ItemInit

Item * ItemInit(void * value, ItemValueOperations * value_ops)

Initializes the Item.

Returns

The initialized Item

Parameters

Parameter Type Description
value void * The value to put into the Item.
value_ops ItemValueOperations * A struct containing operations that can be performed on the value of the Item.

ItemInitV2

Item * ItemInitV2(void * value, const void * type_id, ItemValueOperations * value_ops)

ItemFree

void ItemFree(Item * item)

Frees an Item.

Parameters

Parameter Type Description
item Item * The Item to free.

ItemPrint

void ItemPrint(Item * item)

Prints an Item.

Parameters

Parameter Type Description
item Item * The Item to print.

ItemToString

char * ItemToString(Item * item)

Converts and Item to a String, uses the ItemToStringFunction.

Returns

a string representation of the item.

Parameters

Parameter Type Description
item Item * The Item to convert to string.

ItemDuplicate

Item * ItemDuplicate(Item * item)

ItemHash

u_int32_t ItemHash(Item * item)

ItemEquivalence

bool ItemEquivalence(Item * item1, Item * item2)

ListInit

List * ListInit(u_int32_t initial_capacity, u_int8_t resize_multiple)

Initializes a List.

Returns

The initialized List.

Parameters

Parameter Type Description
initial_capacity u_int32_t How large for the List to start as.
resize_multiple u_int8_t What multiple to resize the list after it reaches capacity.

ListInitDefault

List * ListInitDefault(void)

Initializes a List with sane defaults, see ListInit for more customization.

Returns

The initialized List.


ListAddFirst

void ListAddFirst(List * list, Item * item)

Add an Item to the front of the List.

Parameters

Parameter Type Description
list List * The List to add an Item to.
item Item * The Item to add to the List.

ListAddLast

void ListAddLast(List * list, Item * item)

Add an Item to the last available spot of the List.

Parameters

Parameter Type Description
list List * The List to add an Item to.
item Item * The Item to add to the List.

ListAddAtIndex

void ListAddAtIndex(List * list, Item * item, u_int32_t index)

Add an Item to a specific index of the list.

Parameters

Parameter Type Description
list List * The List to add an Item to.
item Item * The Item to add to the List.
index u_int32_t The index of the List to place the Item into.

ListRemoveAtIndex

void ListRemoveAtIndex(List * list, u_int32_t index, bool free)

Remove an Item at a specific index.

Parameters

Parameter Type Description
list List * The List to remove an Item from.
index u_int32_t The index of the List to remove the Item from.
free bool Do you want to free the Item as well.

ListRemoveFirst

void ListRemoveFirst(List * list)

Remove the first Item from a List.

Parameters

Parameter Type Description
list List * The List to remove an Item from.

ListRemoveLast

void ListRemoveLast(List * list)

Remove the last Item from a List.

Parameters

Parameter Type Description
list List * The List to remove an Item from.

ListGetAtIndex

Item * ListGetAtIndex(List * list, u_int32_t index)

Get an Item from a List at a specific Index.

Returns

The Item from the List at a specific Index.

Parameters

Parameter Type Description
list List * The List to get an Item from.
index u_int32_t The index at which to get an Item from.

ListGetFirst

Item * ListGetFirst(List * list)

Get the first Item from a List.

Returns

The first Item from the specified List.

Parameters

Parameter Type Description
list List * The List to get an Item from.

ListPopAtIndex

Item * ListPopAtIndex(List * list, u_int32_t index)

Get and remove an Item from a List.

Returns

The Item from the List.

Parameters

Parameter Type Description
list List * The List to get an Item from.
index u_int32_t The index at which to get an Item from.

ListPopFirst

Item * ListPopFirst(List * list)

Pop the First Item from a List.

Returns

The Item from the List.

Parameters

Parameter Type Description
list List * The List to get an Item from.

ListPrintInfo

void ListPrintInfo(List * list)

Print info of the List (current size, etc...).

Parameters

Parameter Type Description
list List * The List to print info of.

HashMapItemInit

HashMapItem * HashMapItemInit(char * key, Item * item)

Initializes as HashMapItem.

Returns

The Initialized HashMapItem.

Parameters

Parameter Type Description
key char * The string key of HashMapItem.
item Item * The corresponding value to the hashed key.

HashMapItemDuplicate

HashMapItem * HashMapItemDuplicate(HashMapItem * hashmap_item)

HashMapItemFree

void HashMapItemFree(HashMapItem * hashmap_item, bool deep)

Frees a HashMapItem, can optional deep free by freeing the Item as well.

Parameters

Parameter Type Description
hashmap_item HashMapItem * The HashMapItem to free.
deep bool If true, will free the Item in the HashMapItem.

HashMapItemPrint

void HashMapItemPrint(HashMapItem * hashmap_item)

Prints a HashMapItem.

Parameters

Parameter Type Description
hashmap_item HashMapItem * The HashMapItem to print.

HashMapGet

HashMapItem * HashMapGet(HashMap * map, char * key)

Get a HashMapItem based on a key.

Returns

The HashMapItem from the HashMap (if found).

Parameters

Parameter Type Description
map HashMap * The HashMap to look into.
key char * the key to use to look up the item.

HashMapInit

HashMap * HashMapInit(u_int32_t initial_capacity, u_int8_t resize_multiple, HashFunction * hashFunction, bool force_lowercase)

Initialize a fresh HashMap.

Returns

The initialized HashMap.

Parameters

Parameter Type Description
initial_capacity u_int32_t The starting capacity of the HashMap.
resize_multiple u_int8_t What resizing multiple to use when the HashMap is at capacity.
hashFunction HashFunction * A pointer to a function for hashing string to an index.
force_lowercase bool Do we want to force lowercase conversion for all keys.

HashMapInitDefault

HashMap * HashMapInitDefault(void)

Initialize a fresh HashMap with sane defaults, see HashMapInit for more customization.

Returns

The initialized HashMap.


HashMapInsert

void HashMapInsert(HashMap * map, HashMapItem * entry)

Insert a HashMapItem into a HashMap.

Parameters

Parameter Type Description
map HashMap * The HashMap that should be inserted into.
entry HashMapItem * The HashMapItem entry to be inserted into the HashMap.

HashMapRemove

void HashMapRemove(HashMap * map, char * key)

Remove a HashMapItem from a HashMap.

Parameters

Parameter Type Description
map HashMap * The HashMap that will have a HashMapItem removed from.
key char * The key of the HashMapItem to be removed.

HashMapGetValueDirect

void * HashMapGetValueDirect(HashMap * map, char * key)

Get a value directly from a lookup instead of receiving HashMapItem then unwrapping to Item, then unwarapping to value.

Returns

The direct void * value.

Parameters

Parameter Type Description
map HashMap * The HashMap to look into.
key char * The lookup key.

LinkedListInit

LinkedList * LinkedListInit()

IsLinkedListEmpty

bool IsLinkedListEmpty(LinkedList * list)

LinkedListAddToFront

void LinkedListAddToFront(LinkedList * list, Item * item)

LinkedListAddToBack

void LinkedListAddToBack(LinkedList * list, Item * item)

LinkedListAddAtIndex

void LinkedListAddAtIndex(LinkedList * list, Item * item, u_int64_t index)

LinkedListFree

void LinkedListFree(void * list)

LinkedListDeleteAtIndex

void LinkedListDeleteAtIndex(LinkedList * list, u_int64_t index)

LinkedListDeleteBack

void LinkedListDeleteBack(LinkedList * list)

LinkedListDeleteFront

void LinkedListDeleteFront(LinkedList * list)

ComplexHashMapInit

ComplexHashMap * ComplexHashMapInit(u_int32_t initial_capacity, u_int8_t resize_multiple)

ComplexHashMapInitDefault

ComplexHashMap * ComplexHashMapInitDefault(void)

ComplexHashMapFree

void ComplexHashMapFree(void * map)

ComplexHashMapGet

Item * ComplexHashMapGet(ComplexHashMap * map, Item * key)

ComplexHashMapInsert

void ComplexHashMapInsert(ComplexHashMap * map, Item * key, Item * value)

ComplexHashMapRemove

void ComplexHashMapRemove(ComplexHashMap * map, Item * key)

ComplexHashMapDuplicate

void * ComplexHashMapDuplicate(void * map)

Variables


ItemValueStringOperations

ItemValueOperations ItemValueStringOperations

ItemValueIntOperations

ItemValueOperations ItemValueIntOperations

ItemValueListOperations

ItemValueOperations ItemValueListOperations

ItemValueHashMapOperations

ItemValueOperations ItemValueHashMapOperations

ItemValueComplexHashMapOperations

ItemValueOperations ItemValueComplexHashMapOperations

ItemValueLinkedListOperations

ItemValueOperations ItemValueLinkedListOperations

SL_COLLECTIONS_TYPE_STRING

const char SL_COLLECTIONS_TYPE_STRING

SL_COLLECTIONS_TYPE_INT

const char SL_COLLECTIONS_TYPE_INT

SL_COLLECTIONS_TYPE_LIST

const char SL_COLLECTIONS_TYPE_LIST

SL_COLLECTIONS_TYPE_HASHMAP

const char SL_COLLECTIONS_TYPE_HASHMAP

SL_COLLECTIONS_TYPE_COMPLEX_HASHMAP

const char SL_COLLECTIONS_TYPE_COMPLEX_HASHMAP

SL_COLLECTIONS_TYPE_LINKED_LIST

const char SL_COLLECTIONS_TYPE_LINKED_LIST

test

Variables

Return Name Description
str apple
list fruits_list
tuple fruits

apple

str apple =  "apple"

fruits_list

list fruits_list =  [apple, "banana", "cherry"]

fruits

tuple fruits =  (fruits_list, "banana", "cherry")

Item

#include <standardloop/collections.h>
struct Item

The Item struct, contains a value of any kind, and a function to free the value and print the value.

Public Attributes

Return Name Description
void * value The value itself.
const void * type_id What type is the value, by using const char memory addresses.
ItemValueOperations * value_ops Common Operations to be performed on the value.

value

void * value

The value itself.


type_id

const void * type_id

What type is the value, by using const char memory addresses.


value_ops

ItemValueOperations * value_ops

Common Operations to be performed on the value.

List

#include <standardloop/collections.h>
struct List

The List struct, contains a header for size, capacity, and resizing multiple and then a List of Items.

Public Attributes

Return Name Description
u_int32_t size The current size of the List.
u_int32_t capacity The capacity of the List, can be expanded.
u_int8_t resize_multiple The resizing multiple of the List, if the list is at capacity, what multiple to resize it
Item ** items The list of Items.

size

u_int32_t size

The current size of the List.


capacity

u_int32_t capacity

The capacity of the List, can be expanded.


resize_multiple

u_int8_t resize_multiple

The resizing multiple of the List, if the list is at capacity, what multiple to resize it


items

Item ** items

Type: Item **

The list of Items.

HashMap

#include <standardloop/collections.h>
struct HashMap

The HashMap struct, contains a header for size, capacity, and resizing multiple. Has a list of entries and a pointer to a hashing function.

Public Attributes

Return Name Description
u_int32_t size The current size (number of entries) of the HashMap.
u_int32_t capacity How large the HashMap can get before it needs to be resized.
u_int8_t resize_multiple If the HashMap needs to be resized, what should the resizing multiple be
u_int32_t collision_count How many collisions have occured.
HashMapItem ** entries The List entries in the HashMap.
HashFunction * hashFunction The function this HashMap uses to Hash strings.
bool force_lowercase Should only lowercase be considered, for example "THIS" and "this" are both hashed to the same value.

size

u_int32_t size

The current size (number of entries) of the HashMap.


capacity

u_int32_t capacity

How large the HashMap can get before it needs to be resized.


resize_multiple

u_int8_t resize_multiple

If the HashMap needs to be resized, what should the resizing multiple be


collision_count

u_int32_t collision_count

How many collisions have occured.


entries

HashMapItem ** entries

Type: HashMapItem **

The List entries in the HashMap.


hashFunction

HashFunction * hashFunction

Type: HashFunction *

The function this HashMap uses to Hash strings.


force_lowercase

bool force_lowercase

Should only lowercase be considered, for example "THIS" and "this" are both hashed to the same value.

LinkedList

struct LinkedList

Public Attributes

Return Name Description
LinkedListNode * head
u_int32_t size

LinkedListNode * head

size

u_int32_t size

HashMapItem

#include <standardloop/collections.h>
struct HashMapItem

The HashMapItem struct. Contains the key, the value, and a next field for collisions.

Public Attributes

Return Name Description
char * key The key for a hashed value.
Item * item the item hashed to the key.
struct hashMapItem * next If a collision occurs, the next field - linked list for collisions.

key

char * key

The key for a hashed value.


item

Item * item

Type: Item *

the item hashed to the key.


next

struct hashMapItem * next

If a collision occurs, the next field - linked list for collisions.

ComplexHashMap

struct ComplexHashMap

Public Attributes

Return Name Description
u_int32_t size The current size (number of entries) of the HashMap.
u_int32_t capacity How large the HashMap can get before it needs to be resized.
u_int8_t resize_multiple If the HashMap needs to be resized, what should the resizing multiple be
u_int32_t collision_count How many collisions have occured.
ComplexHashMapItem ** entries The List entries in the HashMap.

size

u_int32_t size

The current size (number of entries) of the HashMap.


capacity

u_int32_t capacity

How large the HashMap can get before it needs to be resized.


resize_multiple

u_int8_t resize_multiple

If the HashMap needs to be resized, what should the resizing multiple be


collision_count

u_int32_t collision_count

How many collisions have occured.


entries

ComplexHashMapItem ** entries

The List entries in the HashMap.

LinkedListNode

struct LinkedListNode

Public Attributes

Return Name Description
struct linkedListNode * next
Item * item

next

struct linkedListNode * next

item

Item * item

Type: Item *

ItemValueOperations

struct ItemValueOperations

Public Attributes

Return Name Description
ItemValueFreeFunction * freeFunction A function to free the value.
ItemValuePrintFunction * printFunction A function to print the value.
ItemValueToStringFunction * toStringFunction A function to turn the value.
ItemValueReplicateFunction * duplicateFunction A function deep replicate a value of an item.
ItemValueHashFunction * hashFunction A function to hash the structure
ItemValueEquivalenceFunction * equivalenceFunction A function to check for equivalency

freeFunction

ItemValueFreeFunction * freeFunction

Type: ItemValueFreeFunction *

A function to free the value.


printFunction

ItemValuePrintFunction * printFunction

Type: ItemValuePrintFunction *

A function to print the value.


toStringFunction

ItemValueToStringFunction * toStringFunction

Type: ItemValueToStringFunction *

A function to turn the value.


duplicateFunction

ItemValueReplicateFunction * duplicateFunction

A function deep replicate a value of an item.


hashFunction

ItemValueHashFunction * hashFunction

A function to hash the structure


equivalenceFunction

ItemValueEquivalenceFunction * equivalenceFunction

A function to check for equivalency