Data Structures

sst/elements/genericProc/programs/libcprops/collection.h File Reference

The c collection classes provide plain c implementations of famous data structures and algorithms such as linked lists, hash tables, hash lists and an extensible tree implementation (see graph.h). More...

#include "common.h"
#include "log.h"
#include "common.h"

Go to the source code of this file.

Data Structures

struct  _cp_mapping
struct  _cp_index
struct  _cp_wrap
 lock for collection types - current implementation uses pthread_rwlock_t More...



#define COLLECTION_MODE_PLAIN   0
 use collection defaults
#define COLLECTION_MODE_DEEP   1
 collection copies and deletes elements (keys, values)
#define COLLECTION_MODE_MULTIPLE_VALUES   2
 collection allows non-unique keys
#define COLLECTION_MODE_COPY   4
 collection stores copies of elements (keys, values)
#define COLLECTION_MODE_NOSYNC   8
 no synchronization - suitable for the single threaded situation or if you want to do the synchronization yourself.
#define COLLECTION_MODE_NORESIZE   16
 The collection does not resize underlying hashtables.
#define COLLECTION_MODE_LIST_ORDER   32
 hashlist multiple values are returned in list order (O(N)) rather than insertion order (O(1))
#define COLLECTION_MODE_IN_TRANSACTION   64
 indicates a transaction is in progress
#define COLLECTION_LOCK_NONE   0
 no lock
#define COLLECTION_LOCK_READ   1
 lock for reading
#define COLLECTION_LOCK_WRITE   2
 lock for writing
#define cp_mapping_key(m)   ((m)->key)
#define cp_mapping_value(m)   ((m)->value)
#define cp_malloc   malloc
#define cp_calloc   calloc
#define cp_realloc   realloc
#define cp_free   free
enum  cp_op {
  CP_OP_LT = 1, CP_OP_LE = 2, CP_OP_EQ = 3, CP_OP_NE = 4,
  CP_OP_GE = 5, CP_OP_GT = 6
}
enum  cp_index_type { CP_UNIQUE, CP_MULTIPLE }
typedef void *(* cp_copy_fn )(void *)
 copy function.
typedef void(* cp_destructor_fn )(void *)
 destructor function.
typedef int(* cp_compare_fn )(void *, void *)
 comparator functions implement strcmp semantics - 0 for identical keys, non-zero otherwise.
typedef int(* cp_callback_fn )(void *entry, void *client_prm)
 callback function for iterator callback etc
typedef CPROPS_DLL struct
_cp_mapping 
cp_mapping
typedef int(* cp_mapping_cmp_fn )(cp_mapping *a, cp_mapping *b)
typedef void *(* cp_key_fn )(void *record)
 extract an alternate key from a record for indexing
typedef CPROPS_DLL struct _cp_index cp_index
typedef struct _cp_string *(* cp_serialize_fn )(void *object)
typedef void *(* cp_deserialize_fn )(void *buf, size_t *used)
typedef CPROPS_DLL struct _cp_wrap cp_wrap
 lock for collection types - current implementation uses pthread_rwlock_t
CPROPS_DLL cp_mapping * cp_mapping_create (void *key, void *value)
CPROPS_DLL cp_index * cp_index_create (cp_index_type type, cp_key_fn key, cp_compare_fn cmp)
CPROPS_DLL cp_index * cp_index_copy (cp_index *src)
CPROPS_DLL int cp_index_compare (cp_index *index, void *a, void *b)
CPROPS_DLL cp_wrapcp_wrap_new (void *item, cp_destructor_fn dtr)
CPROPS_DLL void cp_wrap_delete (cp_wrap *wrap)

Detailed Description

The c collection classes provide plain c implementations of famous data structures and algorithms such as linked lists, hash tables, hash lists and an extensible tree implementation (see graph.h).

Behavior in terms of synchronization and member uniqueness may be set on initialization using the appropriate constructor function with the required flags. The default implementations are synchronized, and mostly allow mutliple values with the notable exception of the cp_hashtable and cp_hashlist collections which do not by default. Other subtle differences deriving from data structure characteristics or implementation inconsistencies would suggest reading the inline documentation in the header files for the specific collection you intend to use.

This header file defines macros and function types used commonly throughout the package.


Define Documentation

#define COLLECTION_MODE_NORESIZE   16

The collection does not resize underlying hashtables.

It might make sense to set this temporarily in code sections that shouldn't be unexpectedly slowed down by a resize operation, but resize should be allowed if the table fill factor is expected to go over ~70%, which is the point at which hashtable performace is rumored to start degrading.

Referenced by cp_hashlist_insert_internal(), and cp_hashlist_remove_internal().

#define COLLECTION_MODE_NOSYNC   8

Typedef Documentation

typedef void*(* cp_copy_fn)(void *)

copy function.

In cases where the collection holds copies rather than references to the original objects. To do this you need to provide a copy function for the items.

typedef CPROPS_DLL struct _cp_wrap cp_wrap

lock for collection types - current implementation uses pthread_rwlock_t

_WINDOWS implementation for cp_cond is based on "Strategies for Implementing POSIX Condition Variables on _WINDOWS" by Douglas C. Schmidt and Irfan Pyarali see http://www.cs.wustl.edu/~schmidt/_WINDOWS-cv-1.html