CLibs
Loading...
Searching...
No Matches
set.h File Reference

Sets implemented via a hash table. More...

Go to the source code of this file.

Data Structures

struct  set_item
struct  SetEnumeratedEntry

Macros

#define SET_ITEMCOUNT_LINE_LENGTH   4

Typedefs

typedef struct hash_set Set

Enumerations

enum  SetInsertRV { SETINSERT_INSERTED = 0 , SETINSERT_WAS_IN = 1 }
enum  SetRemoveRV { SETREMOVE_REMOVED = 0 , SETREMOVE_NOT_FOUND = 1 }

Functions

Constructor Setset_init (void)
Constructor Setset_init_cap (size_t capacity)
int set_insert_f (Set *, const void *data, size_t len, PrintFunction func)
int set_insert (Set *, const void *data, size_t len)
int set_remove (Set *, const void *data, size_t len)
bool set_search (const Set *, const void *data, size_t len)
int set_intersection (const Set *, const Set *, Set **result)
int set_intersect (Set *, const Set *intr)
int set_union (const Set *, const Set *, Set **result)
int set_unionize (Set *, const Set *add)
int set_difference (const Set *set, const Set *sub, Set **result)
int set_subtract (Set *set, const Set *sub)
int set_cmp (const Set *, const Set *)
void set_destroy (Set *)
Const size_t set_size (const Set *set)
SetEnumeratedEntry set_get_next (const Set *, int64_t index_last)
void set_print (const Set *)
void set_print_as (const Set *, PrintFunction)

Detailed Description

Sets implemented via a hash table.

Sets contain at most one copy of an item. Items can be of any type – they are treated as arrays of bytes. Their keys are a combination of the number of bytes and each byte of the data.

Parameters
n_items: size_t; number of currently held items in the Set
capacity: size_t; size of items array
items: struct set_item *; array of type set_item

Macro Definition Documentation

◆ SET_ITEMCOUNT_LINE_LENGTH

#define SET_ITEMCOUNT_LINE_LENGTH   4

Max number of items that can be printed on one line in a set.

This may be redefined.

Typedef Documentation

◆ Set

typedef struct hash_set Set

Enumeration Type Documentation

◆ SetInsertRV

Enumerator
SETINSERT_INSERTED 
SETINSERT_WAS_IN 

◆ SetRemoveRV

Enumerator
SETREMOVE_REMOVED 
SETREMOVE_NOT_FOUND 

Function Documentation

◆ set_cmp()

int set_cmp ( const Set * ,
const Set *  )

Compares sets (pretty arbitrarily). First by size, then by items.

Returns
1, 0, -1

◆ set_destroy()

void set_destroy ( Set * )

Frees all memory owned by the Set.

◆ set_difference()

int set_difference ( const Set * set,
const Set * sub,
Set ** result )

Creates a new Set * (saved into result) with the items which are in set but not in sub

Parameters
setset to be subtracted from
subset to be subtracted
resultpointer to a Set * (container)
Returns
RV_ERROR on error, else RV_SUCCESS

◆ set_get_next()

SetEnumeratedEntry set_get_next ( const Set * ,
int64_t index_last )

Iterator over set.

Parameters
index_lastindex of the last iterated element
Returns
SetEnumeratedEntry (tuple of item* and index)

◆ set_init()

Constructor Set * set_init ( void )

Initializes a Set.

Returns
pointer to a new Set

◆ set_init_cap()

Constructor Set * set_init_cap ( size_t capacity)

Initializes a Set with a custom capacity.

Parameters
capacityinitial capacity
Returns
pointer to a new Set

◆ set_insert()

int set_insert ( Set * ,
const void * data,
size_t len )

Inserts a value into the set.

Parameters
datapointer to data
lennumber of bytes in data
Returns
RV_ERROR | RV_EXCEPTION | enum SetInsertRV

◆ set_insert_f()

int set_insert_f ( Set * ,
const void * data,
size_t len,
PrintFunction func )

Inserts a value into the set.

Parameters
datapointer to data
lennumber of bytes in data
funcPrintFunction
Returns
RV_ERROR | RV_EXCEPTION | enum SetInsertRV

◆ set_intersect()

int set_intersect ( Set * ,
const Set * intr )

Leaves the set with only the items which are in intr.

Parameters
intrSecond set
Returns
RV_ERROR if set_remove_item() fails

◆ set_intersection()

int set_intersection ( const Set * ,
const Set * ,
Set ** result )

Creates an intersection of the two sets and shallowly copies the data to a new set, stored under result

Parameters
resultif the val at result is NULL, the function creates a new hash set with the proper values. If the val isn't NULL, the function adds the intersecting values to the hash set in result
Returns
-1 on error, else 0

◆ set_print()

void set_print ( const Set * )

Prints each item using the PrintFunctions they have saved in them.

◆ set_print_as()

void set_print_as ( const Set * ,
PrintFunction  )

Prints each item using the supplied PrintFunction.

◆ set_remove()

int set_remove ( Set * ,
const void * data,
size_t len )

Removes a value from the set.

Parameters
datapointer to data
lensizeof data
Returns
RV_ERROR | RV_EXCEPTION | enum SetRemoveRV

◆ set_search()

bool set_search ( const Set * ,
const void * data,
size_t len )

Searches the set for an element.

Parameters
datadata
lensize of data
Returns
true if present

◆ set_size()

Const size_t set_size ( const Set * set)
Returns
number of items in the set

◆ set_subtract()

int set_subtract ( Set * set,
const Set * sub )

set is left with the items which are not in sub

Parameters
setset to be subtracted from
subset to be subtracted
Returns
RV_ERROR on error, else RV_SUCCESS

◆ set_union()

int set_union ( const Set * ,
const Set * ,
Set ** result )

Creates a union of the two sets, containing all items from both.

Parameters
resultpointer to a Set *
Returns
RV_ERROR on fatal error

◆ set_unionize()

int set_unionize ( Set * ,
const Set * add )

Adds all items from add to the set.

Parameters
addsecond Set
Returns
RV_ERROR on fatal error