summaryrefslogtreecommitdiff
path: root/ckcapi-util.h
blob: 59e660ca18e67465e06e796f92e9c72f98b886e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* 
 * Copyright (C) 2007 Stef Walter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __CKCAPI_UTIL_H__
#define __CKCAPI_UTIL_H__

#include <stdlib.h>


void          ckcapi_reverse_memory       (void* data, size_t length);

/* --------------------------------------------------------------------------------
 * ARRAYS
 */

typedef struct _Array
{
	void* data;
	size_t len;
} 
CkCapiArray;

#define ckcapi_array_append(a,v)		ckcapi_array_append_vals(a, &(v), 1)
#define ckcapi_array_index(a,t,i)		(((t*) (a)->data) [(i)])

CkCapiArray*	ckcapi_array_new			(int zero_terminated, int zero, 
											 size_t element_size);
	
CkCapiArray*	ckcapi_array_sized_new		(int zero_terminated, int zero, 
											 size_t element_size, size_t reserved_size);

void*			ckcapi_array_free			(CkCapiArray* array, int free_segment);

int				ckcapi_array_append_vals	(CkCapiArray* array, const void* data,
											 size_t num);

void			ckcapi_array_remove_index	(CkCapiArray* array, unsigned int index);

void			ckcapi_array_remove_range   (CkCapiArray* array, unsigned int index, 
											  size_t count);


/* --------------------------------------------------------------------------------
 * HASHTABLE
 */

struct _CkCapiHash;
typedef struct _CkCapiHash CkCapiHash;

typedef unsigned int (*CkCapiHashFunc)(const void* key);

typedef int  (*CkCapiHashEqual)(const void* a, const void* b);

typedef void (*CkCapiHashDestroy)(void* val);

CkCapiHash*	 ckcapi_hash_new        (CkCapiHashFunc hash_func, CkCapiHashEqual equal_func);

void		 ckcapi_hash_free       (CkCapiHash* ht, CkCapiHashDestroy destroy_func);

size_t		 ckcapi_hash_count      (CkCapiHash* ht);

void*		 ckcapi_hash_get        (CkCapiHash* ht, const void* key);

int			 ckcapi_hash_set        (CkCapiHash* ht, const void* key, void* val);

void*		 ckcapi_hash_rem        (CkCapiHash* ht, const void* key);

unsigned int ckcapi_hash_pointer    (const void* ptr);

unsigned int ckcapi_hash_data       (const void* data, size_t n_data);

unsigned int ckcapi_hash_integer    (int integer);

#define ckcapi_hash_key(num) \
	(((char*)NULL) + (size_t)(num))

#endif /* __CKCAPI_UTIL_H__ */