libsc  2.8.7
The SC library provides support for parallel scientific applications.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sc_containers.h
Go to the documentation of this file.
1 /*
2  This file is part of the SC Library.
3  The SC Library provides support for parallel scientific applications.
4 
5  Copyright (C) 2010 The University of Texas System
6  Additional copyright (C) 2011 individual authors
7 
8  The SC Library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  The SC Library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with the SC Library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 */
23 
24 #ifndef SC_CONTAINERS_H
25 #define SC_CONTAINERS_H
26 
45 #include <sc.h>
46 
47 SC_EXTERN_C_BEGIN;
48 
49 /* Hash macros from lookup3.c by Bob Jenkins, May 2006, public domain. */
50 
56 #define sc_hash_rot(x,k) (((x) << (k)) | ((x) >> (32 - (k))))
57 
63 #define sc_hash_mix(a,b,c) ((void) \
64  (a -= c, a ^= sc_hash_rot(c, 4), c += b, \
65  b -= a, b ^= sc_hash_rot(a, 6), a += c, \
66  c -= b, c ^= sc_hash_rot(b, 8), b += a, \
67  a -= c, a ^= sc_hash_rot(c,16), c += b, \
68  b -= a, b ^= sc_hash_rot(a,19), a += c, \
69  c -= b, c ^= sc_hash_rot(b, 4), b += a))
70 
76 #define sc_hash_final(a,b,c) ((void) \
77  (c ^= b, c -= sc_hash_rot(b,14), \
78  a ^= c, a -= sc_hash_rot(c,11), \
79  b ^= a, b -= sc_hash_rot(a,25), \
80  c ^= b, c -= sc_hash_rot(b,16), \
81  a ^= c, a -= sc_hash_rot(c, 4), \
82  b ^= a, b -= sc_hash_rot(a,14), \
83  c ^= b, c -= sc_hash_rot(b,24)))
84 
90 typedef unsigned int (*sc_hash_function_t) (const void *v, const void *u);
91 
98 typedef int (*sc_equal_function_t) (const void *v1,
99  const void *v2, const void *u);
100 
106 typedef int (*sc_hash_foreach_t) (void **v, const void *u);
107 
116 typedef struct sc_array
117 {
118  /* interface variables */
119  size_t elem_size;
120  size_t elem_count;
122  /* implementation variables */
123  ssize_t byte_alloc;
128  char *array;
129 }
131 
133 #define SC_ARRAY_IS_OWNER(a) ((a)->byte_alloc >= 0)
134 
136 #define SC_ARRAY_BYTE_ALLOC(a) ((size_t) \
137  (SC_ARRAY_IS_OWNER (a) ? (a)->byte_alloc : -((a)->byte_alloc + 1)))
138 
145 size_t sc_array_memory_used (sc_array_t * array, int is_dynamic);
146 
151 sc_array_t *sc_array_new (size_t elem_size);
152 
159 sc_array_t *sc_array_new_count (size_t elem_size, size_t elem_count);
160 
162 #define sc_array_new_size(s,c) (sc_array_new_count ((s), (c)))
163 
172  size_t offset, size_t length);
173 
181  size_t elem_size, size_t elem_count);
182 
187 
193 
198 void sc_array_init (sc_array_t * array, size_t elem_size);
199 
208  size_t elem_size, size_t elem_count);
209 
218  size_t elem_size, size_t elem_count);
219 
231  size_t offset, size_t length);
232 
246  sc_array_t * array,
247  size_t elem_size,
248  size_t elem_count);
249 
259 void sc_array_init_data (sc_array_t * view, void *base,
260  size_t elem_size, size_t elem_count);
261 
268 void sc_array_memset (sc_array_t * array, int c);
269 
279 void sc_array_reset (sc_array_t * array);
280 
289 
299 void sc_array_rewind (sc_array_t * array, size_t new_count);
300 
311 void sc_array_resize (sc_array_t * array, size_t new_count);
312 
320 void sc_array_copy (sc_array_t * dest, sc_array_t * src);
321 
332 void sc_array_copy_into (sc_array_t * dest, size_t dest_offset,
333  sc_array_t * src);
334 
349 void sc_array_move_part (sc_array_t * dest, size_t dest_offset,
350  sc_array_t * src, size_t src_offset,
351  size_t count);
352 
357 void sc_array_sort (sc_array_t * array,
358  int (*compar) (const void *,
359  const void *));
360 
367  int (*compar) (const void *,
368  const void *));
369 
377  sc_array_t * other);
378 
384 void sc_array_uniq (sc_array_t * array,
385  int (*compar) (const void *,
386  const void *));
387 
394 ssize_t sc_array_bsearch (sc_array_t * array,
395  const void *key,
396  int (*compar) (const void *,
397  const void *));
398 
404 typedef size_t (*sc_array_type_t) (sc_array_t * array,
405  size_t index, void *data);
406 
423 void sc_array_split (sc_array_t * array, sc_array_t * offsets,
424  size_t num_types, sc_array_type_t type_fn,
425  void *data);
426 
435 
448  sc_array_t * newindices, int keepperm);
449 
453 unsigned int sc_array_checksum (sc_array_t * array);
454 
470  void *temp,
471  int (*compar) (const void *,
472  const void *));
473 
485  void *result,
486  int (*compar) (const void *,
487  const void *));
488 
494 /*@unused@*/
495 static inline void *
496 sc_array_index (sc_array_t * array, size_t iz)
497 {
498  SC_ASSERT (iz < array->elem_count);
499 
500  return (void *) (array->array + array->elem_size * iz);
501 }
502 
509 /*@unused@*/
510 static inline void *
511 sc_array_index_null (sc_array_t * array, size_t iz)
512 {
513  SC_ASSERT (iz <= array->elem_count);
514 
515  return iz == array->elem_count ? NULL :
516  (void *) (array->array + array->elem_size * iz);
517 }
518 
522 /*@unused@*/
523 static inline void *
524 sc_array_index_int (sc_array_t * array, int i)
525 {
526  SC_ASSERT (i >= 0 && (size_t) i < array->elem_count);
527 
528  return (void *) (array->array + (array->elem_size * (size_t) i));
529 }
530 
534 /*@unused@*/
535 static inline void *
536 sc_array_index_long (sc_array_t * array, long l)
537 {
538  SC_ASSERT (l >= 0 && (size_t) l < array->elem_count);
539 
540  return (void *) (array->array + (array->elem_size * (size_t) l));
541 }
542 
546 /*@unused@*/
547 static inline void *
548 sc_array_index_ssize_t (sc_array_t * array, ssize_t is)
549 {
550  SC_ASSERT (is >= 0 && (size_t) is < array->elem_count);
551 
552  return (void *) (array->array + (array->elem_size * (size_t) is));
553 }
554 
558 /*@unused@*/
559 static inline void *
560 sc_array_index_int16 (sc_array_t * array, int16_t i16)
561 {
562  SC_ASSERT (i16 >= 0 && (size_t) i16 < array->elem_count);
563 
564  return (void *) (array->array + (array->elem_size * (size_t) i16));
565 }
566 
570 /*@unused@*/
571 static inline size_t
572 sc_array_position (sc_array_t * array, void *element)
573 {
574  ptrdiff_t position;
575 
576  SC_ASSERT (array->array <= (char *) element);
577  SC_ASSERT (((char *) element - array->array) %
578  (ptrdiff_t) array->elem_size == 0);
579 
580  position = ((char *) element - array->array) / (ptrdiff_t) array->elem_size;
581  SC_ASSERT (0 <= position && position < (ptrdiff_t) array->elem_count);
582 
583  return (size_t) position;
584 }
585 
591 /*@unused@*/
592 static inline void *
593 sc_array_pop (sc_array_t * array)
594 {
595  SC_ASSERT (SC_ARRAY_IS_OWNER (array));
596  SC_ASSERT (array->elem_count > 0);
597 
598  return (void *) (array->array + (array->elem_size * --array->elem_count));
599 }
600 
605 /*@unused@*/
606 static inline void *
607 sc_array_push_count (sc_array_t * array, size_t add_count)
608 {
609  const size_t old_count = array->elem_count;
610  const size_t new_count = old_count + add_count;
611 
612  SC_ASSERT (SC_ARRAY_IS_OWNER (array));
613 
614  if (array->elem_size * new_count > (size_t) array->byte_alloc) {
615  sc_array_resize (array, new_count);
616  }
617  else {
618  array->elem_count = new_count;
619  }
620 
621  return (void *) (array->array + array->elem_size * old_count);
622 }
623 
628 /*@unused@*/
629 static inline void *
630 sc_array_push (sc_array_t * array)
631 {
632  return sc_array_push_count (array, 1);
633 }
634 
641 typedef struct sc_mstamp
642 {
643  size_t elem_size;
644  size_t per_stamp;
645  size_t stamp_size;
646  size_t cur_snext;
647  char *current;
649 }
651 
670  size_t stamp_unit, size_t elem_size);
671 
677 
688 
698 
704 
714 typedef struct sc_mempool
715 {
716  /* interface variables */
717  size_t elem_size;
718  size_t elem_count;
721  /* implementation variables */
724 }
726 
732 
738 sc_mempool_t *sc_mempool_new (size_t elem_size);
739 
747 
753  size_t elem_size);
754 
760 
767 
773 
778 
783 /*@unused@*/
784 static inline void *
785 sc_mempool_alloc (sc_mempool_t * mempool)
786 {
787  void *ret;
788  sc_array_t *freed = &mempool->freed;
789 
790  ++mempool->elem_count;
791 
792  if (freed->elem_count > 0) {
793  ret = *(void **) sc_array_pop (freed);
794  }
795  else {
796  ret = sc_mstamp_alloc (&mempool->mstamp);
797  if (mempool->zero_and_persist) {
798  memset (ret, 0, mempool->elem_size);
799  }
800  }
801 
802 #ifdef SC_ENABLE_DEBUG
803  if (!mempool->zero_and_persist) {
804  memset (ret, -1, mempool->elem_size);
805  }
806 #endif
807 
808  return ret;
809 }
810 
814 /*@unused@*/
815 static inline void
816 sc_mempool_free (sc_mempool_t * mempool, void *elem)
817 {
818  sc_array_t *freed = &mempool->freed;
819 
820  SC_ASSERT (mempool->elem_count > 0);
821 
822 #ifdef SC_ENABLE_DEBUG
823  if (!mempool->zero_and_persist) {
824  memset (elem, -1, mempool->elem_size);
825  }
826 #endif
827 
828  --mempool->elem_count;
829 
830  *(void **) sc_array_push (freed) = elem;
831 }
832 
835 typedef struct sc_link
836 {
837  void *data;
838  struct sc_link *next;
839 }
841 
844 typedef struct sc_list
845 {
846  /* interface variables */
847  size_t elem_count;
851  /* implementation variables */
854 }
856 
863 size_t sc_list_memory_used (sc_list_t * list, int is_dynamic);
864 
871 
877 
883 void sc_list_init (sc_list_t * list, sc_mempool_t * allocator);
884 
890 void sc_list_reset (sc_list_t * list);
891 
896 void sc_list_unlink (sc_list_t * list);
897 
903 sc_link_t *sc_list_prepend (sc_list_t * list, void *data);
904 
910 sc_link_t *sc_list_append (sc_list_t * list, void *data);
911 
919  sc_link_t * pred, void *data);
920 
928 void *sc_list_remove (sc_list_t * list, sc_link_t * pred);
929 
934 void *sc_list_pop (sc_list_t * list);
935 
939 typedef struct sc_hash
940 {
941  /* interface variables */
942  size_t elem_count;
943  void *user_data;
945  /* implementation variables */
949  size_t resize_checks;
950  size_t resize_actions;
953 }
955 
962 unsigned int sc_hash_function_string (const void *s, const void *u);
963 
969 
978  sc_equal_function_t equal_fn,
979  void *user_data, sc_mempool_t * allocator);
980 
987 
994 
1001 
1009 
1015 
1024 int sc_hash_lookup (sc_hash_t * hash, void *v, void ***found);
1025 
1034 int sc_hash_insert_unique (sc_hash_t * hash, void *v,
1035  void ***found);
1036 
1044 int sc_hash_remove (sc_hash_t * hash, void *v, void **found);
1045 
1052 
1058 void sc_hash_print_statistics (int package_id,
1059  int log_priority,
1060  sc_hash_t * hash);
1061 
1063 typedef struct sc_hash_array_data sc_hash_array_data_t;
1064 
1068 typedef struct sc_hash_array
1069 {
1070  /* interface variables */
1071  void *user_data;
1073  /* implementation variables */
1077 }
1079 
1085 
1093  sc_hash_function_t hash_fn,
1094  sc_equal_function_t equal_fn,
1095  void *user_data);
1096 
1101 
1107 
1112 
1123  void *v, size_t *position);
1124 
1138  void *v, size_t *position);
1139 
1145  sc_hash_foreach_t fn);
1146 
1154  sc_array_t * rip);
1155 
1161 typedef struct sc_recycle_array
1162 {
1163  /* interface variables */
1164  size_t elem_count;
1166  /* implementation variables */
1169 }
1171 
1178  size_t elem_size);
1179 
1186 
1196  size_t *position);
1197 
1207  size_t position);
1208 
1209 SC_EXTERN_C_END;
1210 
1211 #endif /* !SC_CONTAINERS_H */
Support for process management (memory allocation, logging, etc.)
void sc_array_permute(sc_array_t *array, sc_array_t *newindices, int keepperm)
Given permutation newindices, permute array in place.
unsigned int(* sc_hash_function_t)(const void *v, const void *u)
Function to compute a hash value of an object.
Definition: sc_containers.h:90
sc_link_t * sc_list_insert(sc_list_t *list, sc_link_t *pred, void *data)
Insert an element after a given list position.
struct sc_hash_array_data sc_hash_array_data_t
Internal context structure for sc_hash_array.
Definition: sc_containers.h:1063
void * sc_hash_array_insert_unique(sc_hash_array_t *hash_array, void *v, size_t *position)
Insert an object into a hash array if it is not contained already.
struct sc_list sc_list_t
The sc_list object provides a linked list.
struct sc_recycle_array sc_recycle_array_t
The sc_recycle_array object provides an array of slots that can be reused.
sc_list_t * sc_list_new(sc_mempool_t *allocator)
Allocate a new, empty linked list.
int sc_hash_array_lookup(sc_hash_array_t *hash_array, void *v, size_t *position)
Check if an object is contained in a hash array.
void sc_mempool_reset(sc_mempool_t *mempool)
Same as sc_mempool_destroy, but does not free the pointer.
void sc_array_init_reshape(sc_array_t *view, sc_array_t *array, size_t elem_size, size_t elem_count)
Initialize an already allocated (or static) view from existing sc_array_t.
void sc_list_init(sc_list_t *list, sc_mempool_t *allocator)
Initialize a list object with an external link allocator.
void sc_array_init(sc_array_t *array, size_t elem_size)
Initializes an already allocated (or static) array structure.
size_t sc_hash_array_memory_used(sc_hash_array_t *ha)
Calculate the memory used by a hash array.
void sc_recycle_array_reset(sc_recycle_array_t *rec_array)
Reset a recycle array.
void sc_array_rewind(sc_array_t *array, size_t new_count)
Shorten an array without reallocating it.
void sc_array_init_data(sc_array_t *view, void *base, size_t elem_size, size_t elem_count)
Initializes an already allocated (or static) view from given plain C data.
int sc_hash_remove(sc_hash_t *hash, void *v, void **found)
Remove an object from a hash table.
void sc_array_init_size(sc_array_t *array, size_t elem_size, size_t elem_count)
Initializes an already allocated (or static) array structure and allocates a given number of elements...
int(* sc_hash_foreach_t)(void **v, const void *u)
Function to call on every data item of a hash table or hash array.
Definition: sc_containers.h:106
void sc_array_copy(sc_array_t *dest, sc_array_t *src)
Copy the contents of one array into another.
void sc_mstamp_reset(sc_mstamp_t *mst)
Free all memory in a stamp structure and all items previously returned.
size_t sc_mstamp_memory_used(sc_mstamp_t *mst)
Return memory size in bytes of all data allocated in the container.
void sc_hash_destroy(sc_hash_t *hash)
Destroy a hash table.
sc_array_t * sc_array_new_data(void *base, size_t elem_size, size_t elem_count)
Creates a new view of an existing plain C array.
void sc_mempool_destroy(sc_mempool_t *mempool)
Destroy a mempool structure.
int sc_hash_insert_unique(sc_hash_t *hash, void *v, void ***found)
Insert an object into a hash table if it is not contained already.
void sc_array_split(sc_array_t *array, sc_array_t *offsets, size_t num_types, sc_array_type_t type_fn, void *data)
Compute the offsets of groups of enumerable types in an array.
void sc_hash_destroy_null(sc_hash_t **phash)
Destroy a hash table and set its pointer to NULL.
sc_mempool_t * sc_mempool_new_zero_and_persist(size_t elem_size)
Creates a new mempool structure with the zero_and_persist option on.
void sc_array_resize(sc_array_t *array, size_t new_count)
Sets the element count to new_count.
void sc_list_unlink(sc_list_t *list)
Unlink all list elements without returning them to the mempool.
unsigned int sc_hash_function_string(const void *s, const void *u)
Compute a hash value from a null-terminated string.
void sc_hash_truncate(sc_hash_t *hash)
Remove all entries from a hash table in O(N).
size_t sc_hash_memory_used(sc_hash_t *hash)
Calculate the memory used by a hash table.
struct sc_array sc_array_t
The sc_array object provides a dynamic array of equal-size elements.
struct sc_hash_array sc_hash_array_t
The sc_hash_array implements an array backed up by a hash table.
void sc_array_destroy_null(sc_array_t **parray)
Destroys an array structure and sets the pointer to NULL.
sc_link_t * sc_list_prepend(sc_list_t *list, void *data)
Insert a list element at the beginning of the list.
void sc_hash_array_foreach(sc_hash_array_t *hash_array, sc_hash_foreach_t fn)
Invoke a callback for every member of the hash array.
void sc_array_reset(sc_array_t *array)
Sets the array count to zero and frees all elements.
size_t sc_mempool_memory_used(sc_mempool_t *mempool)
Calculate the memory used by a memory pool.
void sc_array_sort(sc_array_t *array, int(*compar)(const void *, const void *))
Sorts the array in ascending order wrt.
size_t(* sc_array_type_t)(sc_array_t *array, size_t index, void *data)
Function to determine the enumerable type of an object in an array.
Definition: sc_containers.h:404
void * sc_recycle_array_remove(sc_recycle_array_t *rec_array, size_t position)
Remove an object from the recycle array.
sc_hash_t * sc_hash_new(sc_hash_function_t hash_fn, sc_equal_function_t equal_fn, void *user_data, sc_mempool_t *allocator)
Create a new hash table.
struct sc_hash sc_hash_t
The sc_hash implements a hash table.
void sc_array_uniq(sc_array_t *array, int(*compar)(const void *, const void *))
Removed duplicate entries from a sorted array.
void sc_mempool_destroy_null(sc_mempool_t **pmempool)
Destroy a mempool structure.
void sc_hash_array_truncate(sc_hash_array_t *hash_array)
Remove all elements from the hash array.
struct sc_link sc_link_t
The sc_link structure is one link of a linked list.
void sc_array_destroy(sc_array_t *array)
Destroys an array structure.
void sc_recycle_array_init(sc_recycle_array_t *rec_array, size_t elem_size)
Initialize a recycle array.
sc_array_t * sc_array_new_count(size_t elem_size, size_t elem_count)
Creates a new array structure with a given length (number of elements).
size_t sc_array_memory_used(sc_array_t *array, int is_dynamic)
Calculate the memory used by an array.
struct sc_mempool sc_mempool_t
The sc_mempool object provides a large pool of equal-size elements.
void sc_mstamp_truncate(sc_mstamp_t *mst)
Free all memory in a stamp structure and initialize it anew.
ssize_t sc_array_bsearch(sc_array_t *array, const void *key, int(*compar)(const void *, const void *))
Performs a binary search on an array.
sc_hash_array_t * sc_hash_array_new(size_t elem_size, sc_hash_function_t hash_fn, sc_equal_function_t equal_fn, void *user_data)
Create a new hash array.
void sc_array_init_view(sc_array_t *view, sc_array_t *array, size_t offset, size_t length)
Initializes an already allocated (or static) view from existing sc_array_t.
void sc_mempool_init(sc_mempool_t *mempool, size_t elem_size)
Same as sc_mempool_new, but for an already allocated object.
void sc_array_memset(sc_array_t *array, int c)
Run memset on the array storage.
size_t sc_array_pqueue_add(sc_array_t *array, void *temp, int(*compar)(const void *, const void *))
Adds an element to a priority queue.
void * sc_list_remove(sc_list_t *list, sc_link_t *pred)
Remove an element after a given list position.
void sc_hash_array_rip(sc_hash_array_t *hash_array, sc_array_t *rip)
Extract the array data from a hash array and destroy everything else.
void sc_array_init_count(sc_array_t *array, size_t elem_size, size_t elem_count)
Initializes an already allocated (or static) array structure and allocates a given number of elements...
void sc_hash_unlink(sc_hash_t *hash)
Unlink all hash elements without returning them to the mempool.
sc_mempool_t * sc_mempool_new(size_t elem_size)
Creates a new mempool structure with the zero_and_persist option off.
void sc_mempool_truncate(sc_mempool_t *mempool)
Invalidates all previously returned pointers, resets count to 0.
void sc_hash_unlink_destroy(sc_hash_t *hash)
Same effect as unlink and destroy, but in O(1).
void sc_list_reset(sc_list_t *list)
Remove all elements from a list in O(N).
int sc_array_is_sorted(sc_array_t *array, int(*compar)(const void *, const void *))
Check whether the array is sorted wrt.
struct sc_mstamp sc_mstamp_t
A data container to create memory items of the same size.
void sc_list_destroy(sc_list_t *list)
Destroy a linked list structure in O(N).
int sc_array_is_permutation(sc_array_t *array)
Determine whether array is an array of size_t's whose entries include every integer 0 <= i < array->e...
size_t sc_list_memory_used(sc_list_t *list, int is_dynamic)
Calculate the total memory used by a list.
void sc_hash_array_destroy(sc_hash_array_t *hash_array)
Destroy a hash array.
int sc_hash_array_is_valid(sc_hash_array_t *hash_array)
Check the internal consistency of a hash array.
int sc_hash_lookup(sc_hash_t *hash, void *v, void ***found)
Check if an object is contained in the hash table.
void sc_array_copy_into(sc_array_t *dest, size_t dest_offset, sc_array_t *src)
Copy the contents of one array into some portion of another.
void sc_mstamp_init(sc_mstamp_t *mst, size_t stamp_unit, size_t elem_size)
Initialize a memory stamp container.
void sc_hash_foreach(sc_hash_t *hash, sc_hash_foreach_t fn)
Invoke a callback for every member of the hash table.
void sc_array_truncate(sc_array_t *array)
Sets the array count to zero, but does not free elements.
sc_array_t * sc_array_new_view(sc_array_t *array, size_t offset, size_t length)
Creates a new view of an existing sc_array_t.
sc_array_t * sc_array_new(size_t elem_size)
Creates a new array structure with 0 elements.
#define SC_ARRAY_IS_OWNER(a)
Test whether the sc_array_t owns its array.
Definition: sc_containers.h:133
void * sc_recycle_array_insert(sc_recycle_array_t *rec_array, size_t *position)
Insert an object into the recycle array.
int sc_array_is_equal(sc_array_t *array, sc_array_t *other)
Check whether two arrays have equal size, count, and content.
sc_link_t * sc_list_append(sc_list_t *list, void *data)
Insert a list element at the end of the list.
void sc_hash_print_statistics(int package_id, int log_priority, sc_hash_t *hash)
Compute and print statistical information about the occupancy.
void sc_array_move_part(sc_array_t *dest, size_t dest_offset, sc_array_t *src, size_t src_offset, size_t count)
Copy part of one array into another using memmove (3).
size_t sc_array_pqueue_pop(sc_array_t *array, void *result, int(*compar)(const void *, const void *))
Pops the smallest element from a priority queue.
void * sc_mstamp_alloc(sc_mstamp_t *mst)
Return a new item.
int(* sc_equal_function_t)(const void *v1, const void *v2, const void *u)
Function to check equality of two objects.
Definition: sc_containers.h:98
unsigned int sc_array_checksum(sc_array_t *array)
Computes the adler32 checksum of array data (see zlib documentation).
void * sc_list_pop(sc_list_t *list)
Remove an element from the front of the list.
The sc_array object provides a dynamic array of equal-size elements.
Definition: sc_containers.h:117
size_t elem_count
number of valid elements
Definition: sc_containers.h:120
size_t elem_size
size of a single element
Definition: sc_containers.h:119
char * array
linear array to store elements
Definition: sc_containers.h:128
ssize_t byte_alloc
number of allocated bytes or -(number of viewed bytes + 1) if this is a view: the "+ 1" distinguishes...
Definition: sc_containers.h:123
The sc_hash_array implements an array backed up by a hash table.
Definition: sc_containers.h:1069
sc_hash_array_data_t * internal_data
Private context data.
Definition: sc_containers.h:1076
sc_hash_t * h
Hash map pointing into element array.
Definition: sc_containers.h:1075
void * user_data
Context passed by the user.
Definition: sc_containers.h:1071
sc_array_t a
Array storing the elements.
Definition: sc_containers.h:1074
The sc_hash implements a hash table.
Definition: sc_containers.h:940
size_t elem_count
total number of objects contained
Definition: sc_containers.h:942
size_t resize_checks
Running count of resize checks.
Definition: sc_containers.h:949
sc_mempool_t * allocator
Must allocate sc_link_t objects.
Definition: sc_containers.h:952
int allocator_owned
Boolean designating allocator ownership.
Definition: sc_containers.h:951
sc_array_t * slots
The slot count is slots->elem_count.
Definition: sc_containers.h:946
sc_hash_function_t hash_fn
Function called to compute the hash value.
Definition: sc_containers.h:947
void * user_data
User data passed to hash function.
Definition: sc_containers.h:943
sc_equal_function_t equal_fn
Function called to check objects for equality.
Definition: sc_containers.h:948
size_t resize_actions
Running count of resize actions.
Definition: sc_containers.h:950
The sc_list object provides a linked list.
Definition: sc_containers.h:845
sc_link_t * first
Pointer to first element in list.
Definition: sc_containers.h:848
int allocator_owned
Boolean to designate owned allocator.
Definition: sc_containers.h:852
size_t elem_count
Number of elements in this list.
Definition: sc_containers.h:847
sc_link_t * last
Pointer to last element in list.
Definition: sc_containers.h:849
sc_mempool_t * allocator
Must allocate objects of sc_link_t.
Definition: sc_containers.h:853
The sc_mempool object provides a large pool of equal-size elements.
Definition: sc_containers.h:715
sc_array_t freed
buffers the freed elements
Definition: sc_containers.h:723
sc_mstamp_t mstamp
fixed-size chunk allocator
Definition: sc_containers.h:722
size_t elem_count
number of valid elements
Definition: sc_containers.h:718
size_t elem_size
size of a single element
Definition: sc_containers.h:717
int zero_and_persist
Boolean; is set in constructor.
Definition: sc_containers.h:719
A data container to create memory items of the same size.
Definition: sc_containers.h:642
size_t cur_snext
Next number within a stamp.
Definition: sc_containers.h:646
size_t stamp_size
Bytes allocated in a stamp.
Definition: sc_containers.h:645
sc_array_t remember
Collects all stamps.
Definition: sc_containers.h:648
size_t per_stamp
Number of items per stamp.
Definition: sc_containers.h:644
char * current
Memory of current stamp.
Definition: sc_containers.h:647
size_t elem_size
Input parameter: size per item.
Definition: sc_containers.h:643
The sc_recycle_array object provides an array of slots that can be reused.
Definition: sc_containers.h:1162
sc_array_t f
Cache of freed objects.
Definition: sc_containers.h:1168
sc_array_t a
Array of objects contained.
Definition: sc_containers.h:1167
size_t elem_count
Number of valid entries.
Definition: sc_containers.h:1164