collection.h File Reference

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

Go to the source code of this file.

Data Structures

struct  _cp_mapping
struct  _cp_index
struct  _cp_wrap
#define COLLECTION_MODE_PLAIN   0
#define COLLECTION_MODE_DEEP   1
#define COLLECTION_MODE_MULTIPLE_VALUES   2
#define COLLECTION_MODE_COPY   4
#define COLLECTION_MODE_NOSYNC   8
#define COLLECTION_MODE_NORESIZE   16
#define COLLECTION_MODE_LIST_ORDER   32
#define COLLECTION_MODE_IN_TRANSACTION   64
#define COLLECTION_LOCK_NONE   0
#define COLLECTION_LOCK_READ   1
#define COLLECTION_LOCK_WRITE   2
#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
#define CP_CLZ_CHAR(x)   cp_clz_char_slow(x)
#define CP_CLZ_LONG_LONG(x)   cp_clz_long_long_slow(x)
typedef void *(*) cp_copy_fn (void *)
typedef void(*) cp_destructor_fn (void *)
typedef int(*) cp_compare_fn (void *, void *)
typedef int(*) cp_callback_fn (void *entry, void *client_prm)
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)
typedef CPROPS_DLL struct
_cp_index 
cp_index
typedef _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
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 }
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.

Definition in file collection.h.


Define Documentation

#define COLLECTION_LOCK_NONE   0

no lock

Definition at line 69 of file collection.h.

Referenced by cp_hashlist_iterator_release(), cp_hashlist_lock_internal(), cp_hashtable_lock_internal(), cp_list_iterator_release(), cp_multimap_contains(), cp_multimap_create_index(), cp_multimap_reindex(), cp_priority_list_lock_internal(), cp_socket_delete(), and cp_socket_select_callback_impl().

#define COLLECTION_LOCK_READ   1

lock for reading

Definition at line 71 of file collection.h.

Referenced by cp_avltree_callback(), cp_avltree_callback_postorder(), cp_avltree_callback_preorder(), cp_avltree_find(), cp_avltree_get(), cp_hashlist_callback(), cp_hashlist_contains(), cp_hashlist_create_iterator(), cp_hashlist_get(), cp_hashlist_item_count(), cp_hashlist_iterator_init(), cp_hashlist_iterator_init_tail(), cp_hashlist_lock_internal(), cp_hashtable_contains(), cp_hashtable_get_by_option(), cp_hashtable_get_keys(), cp_hashtable_get_values(), cp_hashtable_lock_internal(), cp_list_callback(), cp_list_is_empty(), cp_list_lock_internal(), cp_list_search(), cp_multimap_callback(), cp_multimap_callback_by_index(), cp_multimap_callback_postorder(), cp_multimap_callback_preorder(), cp_multimap_find(), cp_multimap_find_by_index(), cp_multimap_get(), cp_multimap_get_by_index(), cp_narytree_callback(), cp_narytree_contains(), cp_narytree_get(), cp_priority_list_is_empty(), cp_priority_list_lock_internal(), cp_rbtree_callback(), cp_rbtree_callback_postorder(), cp_rbtree_callback_preorder(), cp_rbtree_find(), cp_rbtree_get(), cp_rtrie_exact_match(), cp_rtrie_fetch_matches(), cp_rtrie_prefix_match(), cp_rtrie_remove(), cp_rtrie_submatch(), cp_socket_stop_all(), cp_sorted_hash_callback(), cp_sorted_hash_callback_postorder(), cp_sorted_hash_callback_preorder(), cp_sorted_hash_find(), cp_sorted_hash_get(), cp_splaytree_callback(), cp_splaytree_callback_postorder(), cp_splaytree_callback_preorder(), cp_splaytree_find(), cp_thread_pool_stop(), cp_trie_exact_match(), cp_trie_fetch_matches(), cp_trie_prefix_match(), cp_trie_remove(), cp_trie_submatch(), cp_wtrie_exact_match(), cp_wtrie_fetch_matches(), cp_wtrie_prefix_match(), cp_wtrie_remove(), and cp_wtrie_submatch().

#define COLLECTION_LOCK_WRITE   2

lock for writing

Definition at line 73 of file collection.h.

Referenced by cp_avltree_delete(), cp_avltree_insert(), cp_avltree_set_mode(), cp_avltree_share_mempool(), cp_avltree_unlock(), cp_avltree_unset_mode(), cp_avltree_use_mempool(), cp_hashlist_append_by_option(), cp_hashlist_create_iterator(), cp_hashlist_get_head(), cp_hashlist_get_tail(), cp_hashlist_insert_by_option(), cp_hashlist_iterator_append(), cp_hashlist_iterator_init(), cp_hashlist_iterator_init_tail(), cp_hashlist_iterator_insert(), cp_hashlist_iterator_remove(), cp_hashlist_lock_internal(), cp_hashlist_remove_by_option(), cp_hashlist_remove_head_by_option(), cp_hashlist_remove_tail_by_option(), cp_hashlist_set_max_fill_factor(), cp_hashlist_set_min_fill_factor(), cp_hashlist_set_min_size(), cp_hashlist_set_mode(), cp_hashlist_txlock(), cp_hashlist_txunlock(), cp_hashlist_unlock(), cp_hashlist_unset_mode(), cp_hashtable_lock_internal(), cp_hashtable_put_by_option(), cp_hashtable_remove_all(), cp_hashtable_remove_by_mode(), cp_hashtable_resize_thread(), cp_hashtable_set_max_fill_factor(), cp_hashtable_set_min_fill_factor(), cp_hashtable_set_min_size(), cp_hashtable_set_mode(), cp_hashtable_txlock(), cp_hashtable_txunlock(), cp_hashtable_unlock(), cp_hashtable_unset_mode(), cp_list_append(), cp_list_destroy_internal(), cp_list_get_head(), cp_list_get_tail(), cp_list_insert(), cp_list_insert_after(), cp_list_insert_before(), cp_list_iterator_append(), cp_list_iterator_insert(), cp_list_iterator_remove(), cp_list_remove(), cp_list_remove_head(), cp_list_remove_tail(), cp_list_set_mode(), cp_list_share_mempool(), cp_list_txlock(), cp_list_txunlock(), cp_list_unlock(), cp_list_unset_mode(), cp_list_use_mempool(), cp_multimap_create_index(), cp_multimap_insert(), cp_multimap_reindex(), cp_multimap_remove(), cp_multimap_remove_by_index(), cp_multimap_set_mode(), cp_multimap_unlock(), cp_multimap_unset_mode(), cp_multimap_use_mempool(), cp_narytree_delete(), cp_narytree_insert(), cp_narytree_set_mode(), cp_narytree_unlock(), cp_narytree_unset_mode(), cp_priority_list_get_next_by_option(), cp_priority_list_insert_by_option(), cp_priority_list_lock_internal(), cp_priority_list_set_mode(), cp_priority_list_txlock(), cp_priority_list_txunlock(), cp_priority_list_unlock(), cp_priority_list_unset_mode(), cp_rbtree_delete(), cp_rbtree_insert(), cp_rbtree_set_mode(), cp_rbtree_unlock(), cp_rbtree_unset_mode(), cp_rbtree_use_mempool(), cp_rtrie_add(), cp_rtrie_set_mode(), cp_rtrie_share_mempool(), cp_rtrie_unlock(), cp_rtrie_unset_mode(), cp_rtrie_use_mempool(), cp_sorted_hash_delete(), cp_sorted_hash_insert(), cp_sorted_hash_set_mode(), cp_sorted_hash_unlock(), cp_sorted_hash_unset_mode(), cp_splaytree_delete(), cp_splaytree_get(), cp_splaytree_insert(), cp_splaytree_set_mode(), cp_splaytree_share_mempool(), cp_splaytree_unlock(), cp_splaytree_unset_mode(), cp_splaytree_use_mempool(), cp_trie_add(), cp_trie_set_mode(), cp_trie_share_mempool(), cp_trie_unlock(), cp_trie_unset_mode(), cp_trie_use_mempool(), cp_wtrie_add(), cp_wtrie_set_mode(), cp_wtrie_share_mempool(), cp_wtrie_unlock(), cp_wtrie_unset_mode(), and cp_wtrie_use_mempool().

#define COLLECTION_MODE_COPY   4

collection stores copies of elements (keys, values)

Definition at line 46 of file collection.h.

Referenced by cp_hashtable_create_copy_mode(), cp_hashtable_create_entry(), cp_hashtable_put_copy(), cp_heap_push(), cp_http_response_create(), cp_httpclient_set_parameter(), cp_multimap_create_by_option(), cp_multimap_create_index(), cp_multimap_insert(), cp_multimap_reindex(), cp_narytree_insert(), cp_rtrie_add(), cp_sorted_hash_insert(), cp_trie_add(), and cp_wtrie_add().

#define COLLECTION_MODE_DEEP   1

collection copies and deletes elements (keys, values)

Definition at line 42 of file collection.h.

Referenced by cp_hashtable_create_copy_mode(), cp_hashtable_destroy(), cp_hashtable_destroy_deep(), cp_hashtable_destroy_shallow(), cp_heap_destroy(), cp_heap_pop(), cp_http_init(), cp_http_response_create(), cp_httpclient_init(), cp_httpclient_set_parameter(), cp_httpsocket_register_service(), cp_list_destroy_custom(), cp_list_destroy_internal(), cp_list_iterator_remove(), cp_list_remove(), cp_list_remove_head(), cp_log_init(), cp_rtrie_add(), cp_rtrie_remove(), cp_socket_create(), cp_socket_init(), cp_trie_add(), cp_trie_remove(), cp_wtrie_add(), and cp_wtrie_remove().

#define COLLECTION_MODE_IN_TRANSACTION   64

indicates a transaction is in progress

Definition at line 66 of file collection.h.

Referenced by cp_avltree_lock(), cp_avltree_set_mode(), cp_avltree_unlock(), cp_hashlist_lock(), cp_hashlist_set_mode(), cp_hashlist_txlock(), cp_hashlist_txunlock(), cp_hashlist_unlock(), cp_hashtable_lock(), cp_hashtable_set_mode(), cp_hashtable_txlock(), cp_hashtable_txunlock(), cp_hashtable_unlock(), cp_heap_lock(), cp_heap_set_mode(), cp_heap_txlock(), cp_heap_txunlock(), cp_heap_unlock(), cp_list_lock(), cp_list_set_mode(), cp_list_txlock(), cp_list_txunlock(), cp_list_unlock(), cp_multimap_lock(), cp_multimap_set_mode(), cp_multimap_unlock(), cp_narytree_lock(), cp_narytree_set_mode(), cp_narytree_unlock(), cp_priority_list_lock(), cp_priority_list_set_mode(), cp_priority_list_txlock(), cp_priority_list_txunlock(), cp_priority_list_unlock(), cp_rbtree_lock(), cp_rbtree_set_mode(), cp_rbtree_unlock(), cp_rtrie_lock(), cp_rtrie_set_mode(), cp_rtrie_unlock(), cp_sorted_hash_lock(), cp_sorted_hash_set_mode(), cp_sorted_hash_unlock(), cp_splaytree_lock(), cp_splaytree_set_mode(), cp_splaytree_unlock(), cp_trie_lock(), cp_trie_set_mode(), cp_trie_unlock(), cp_wtrie_lock(), cp_wtrie_set_mode(), and cp_wtrie_unlock().

#define COLLECTION_MODE_LIST_ORDER   32

hashlist multiple values are returned in list order (O(N)) rather than insertion order (O(1))

Definition at line 62 of file collection.h.

#define COLLECTION_MODE_MULTIPLE_VALUES   2

collection allows non-unique keys

Definition at line 44 of file collection.h.

Referenced by cp_avltree_dump(), cp_avltree_set_mode(), cp_avltree_unset_mode(), cp_db_connection_pool_create(), cp_hashlist_append_by_option(), cp_hashlist_get(), cp_hashlist_insert_by_option(), cp_hashlist_iterator_append(), cp_hashlist_iterator_insert(), cp_hashlist_iterator_to_key(), cp_http_thread_fn(), cp_list_append(), cp_list_create(), cp_list_create_nosync(), cp_list_insert(), cp_list_insert_after(), cp_list_insert_before(), cp_list_remove(), cp_narytree_set_mode(), cp_narytree_unset_mode(), cp_priority_list_insert_by_option(), cp_rbtree_create_multiple(), cp_rbtree_dump(), cp_rbtree_set_mode(), cp_rbtree_unset_mode(), cp_sorted_hash_dump(), cp_sorted_hash_insert(), cp_sorted_hash_set_mode(), cp_sorted_hash_unset_mode(), cp_splaytree_dump(), cp_splaytree_set_mode(), cp_splaytree_unset_mode(), and lookup_internal().

#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.

Definition at line 57 of file collection.h.

Referenced by cp_hashtable_destroy(), cp_hashtable_put_by_option(), and cp_hashtable_remove_by_mode().

#define COLLECTION_MODE_NOSYNC   8

no synchronization - suitable for the single threaded situation or if you want to do the synchronization yourself.

Definition at line 49 of file collection.h.

Referenced by cp_avltree_create(), cp_avltree_create_by_option(), cp_avltree_lock(), cp_avltree_set_mode(), cp_avltree_unset_mode(), cp_avltree_use_mempool(), cp_db_connection_pool_create(), cp_hashlist_create_by_option(), cp_hashlist_iterator_append(), cp_hashlist_iterator_insert(), cp_hashlist_iterator_remove(), cp_hashlist_lock(), cp_hashlist_set_mode(), cp_hashlist_txlock(), cp_hashlist_txunlock(), cp_hashlist_unlock(), cp_hashlist_unset_mode(), cp_hashtable_lock(), cp_hashtable_put_by_option(), cp_hashtable_remove_by_mode(), cp_hashtable_set_mode(), cp_hashtable_txlock(), cp_hashtable_txunlock(), cp_hashtable_unset_mode(), cp_heap_create_by_option(), cp_heap_lock(), cp_heap_set_mode(), cp_heap_txlock(), cp_heap_txunlock(), cp_heap_unset_mode(), cp_http_response_create(), cp_http_thread_fn(), cp_httpclient_set_parameter(), cp_list_create_internal(), cp_list_create_nosync(), cp_list_iterator_append(), cp_list_iterator_insert(), cp_list_iterator_remove(), cp_list_lock(), cp_list_set_mode(), cp_list_txlock(), cp_list_txunlock(), cp_list_unset_mode(), cp_list_use_mempool(), cp_log_init(), cp_multimap_create_by_option(), cp_multimap_create_index(), cp_multimap_destroy(), cp_multimap_insert(), cp_multimap_lock(), cp_multimap_set_mode(), cp_multimap_unset_mode(), cp_multimap_use_mempool(), cp_narytree_create_by_option(), cp_narytree_lock(), cp_narytree_set_mode(), cp_narytree_unset_mode(), cp_priority_list_create_by_option(), cp_priority_list_insert_by_option(), cp_rbtree_create(), cp_rbtree_create_by_option(), cp_rbtree_lock(), cp_rbtree_set_mode(), cp_rbtree_unset_mode(), cp_rbtree_use_mempool(), cp_rtrie_create_rtrie(), cp_rtrie_lock(), cp_rtrie_set_mode(), cp_rtrie_unset_mode(), cp_rtrie_use_mempool(), cp_sorted_hash_create(), cp_sorted_hash_create_by_option(), cp_sorted_hash_lock(), cp_sorted_hash_set_mode(), cp_sorted_hash_unset_mode(), cp_splaytree_create(), cp_splaytree_create_by_option(), cp_splaytree_lock(), cp_splaytree_set_mode(), cp_splaytree_unset_mode(), cp_splaytree_use_mempool(), cp_trie_create_trie(), cp_trie_lock(), cp_trie_set_mode(), cp_trie_unset_mode(), cp_trie_use_mempool(), cp_wtrie_create_wtrie(), cp_wtrie_lock(), cp_wtrie_set_mode(), cp_wtrie_unset_mode(), and cp_wtrie_use_mempool().

#define COLLECTION_MODE_PLAIN   0

use collection defaults

Definition at line 40 of file collection.h.


Typedef Documentation

typedef int(*) cp_callback_fn(void *entry, void *client_prm)

callback function for iterator callback etc

Definition at line 108 of file collection.h.

typedef int(*) cp_compare_fn(void *, void *)

comparator functions implement strcmp semantics - 0 for identical keys, non-zero otherwise.

Definition at line 103 of file collection.h.

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.

Definition at line 92 of file collection.h.

typedef void(*) cp_destructor_fn(void *)

destructor function.

Definition at line 97 of file collection.h.

typedef void*(*) cp_key_fn(void *record)

extract an alternate key from a record for indexing

Definition at line 127 of file collection.h.

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


Generated on Mon Dec 5 23:00:22 2011 for cprops by  doxygen 1.4.7