Diffusion C API  6.3.3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
set.h File Reference

A simple set implementation, based on hash.h. More...

Data Structures

struct  set_entry_s
 This structure represents an entry in the set. More...
 
struct  set_s
 This respresents a set. More...
 

Typedefs

typedef struct set_entry_s SET_ENTRY_T
 This structure represents an entry in the set.
 
typedef struct set_s SET_T
 This respresents a set.
 

Functions

SET_Tset_new (const unsigned long slots)
 Create a new set with the given number of slots. More...
 
SET_Tset_new_string (const unsigned long slots)
 Create a new set which holds strings (pointers to char).
 
SET_Tset_new_int (const unsigned long slots)
 Create a new set which holds pointers to integers.
 
void * set_add_int (SET_T *set, const int val)
 Helper to add integers to sets.
 
void set_free (SET_T *set)
 Frees memory (including values) associated with a set. More...
 
void * set_add (SET_T *set, const void *val)
 Add a value to a set. More...
 
void * set_del (SET_T *set, const void *val)
 Remove a value from the set. More...
 
void * set_contains (const SET_T *set, const void *val)
 Test whether a set contains a given value. More...
 
void ** set_values (const SET_T *set)
 Obtains all values currently in the set. More...
 
SET_Tset_dup (const SET_T *set)
 Create a deep copy of a set. More...
 

Detailed Description

A simple set implementation, based on hash.h.

Copyright © 2014, 2015 Push Technology Ltd., All Rights Reserved.

Use is subject to license terms.

NOTICE: All information contained herein is, and remains the property of Push Technology. The intellectual and technical concepts contained herein are proprietary to Push Technology and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.

Function Documentation

void* set_add ( SET_T set,
const void *  val 
)

Add a value to a set.

If the set already contains the value, a pointer to the value in the set is returned.

Parameters
setThe set to which the value will be added.
valThe value to store.
Return values
void *If the value already exists in the set.
NULLIf the value did not already exist in the set.
void* set_contains ( const SET_T set,
const void *  val 
)

Test whether a set contains a given value.

Parameters
setThe set to be searched for the value.
valThe value which is to be searched for.
Return values
void *The value, if found.
NULLIf the value was not found.
void* set_del ( SET_T set,
const void *  val 
)

Remove a value from the set.

Parameters
setThe set from which the value will be removed.
valThe value to be removed from the set.
Return values
void *The value which was removed. The caller should free this value.
NULLIf the value was not found.
SET_T* set_dup ( const SET_T set)

Create a deep copy of a set.

Parameters
setThe set to copy.
Returns
A copy of the set.
void set_free ( SET_T set)

Frees memory (including values) associated with a set.

This function can free all memory associated with a set.

Parameters
setThe set to be freed.
SET_T* set_new ( const unsigned long  slots)

Create a new set with the given number of slots.

Parameters
slotsThe number of slots available in the set. Values hash to a slot, and if a slot already contains a value which yields the same hash, it is chained to other entries in the bucket.
Return values
SET_T *Returns a pointer to a SET_T structure.
NULLIf the set cannot be created.
void** set_values ( const SET_T set)

Obtains all values currently in the set.

Parameters
setThe set to be inspected.
Returns
A NULL-terminated array of all values in the set. Call free() on the array when it is no longer required; values are pointers into the set and should not be freed.