Debian Codegraph @

doc/ck_ht_init

raw
1 .\"
2 .\" Copyright 2012-2013 Samy Al Bahra.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\"
27 .Dd March 28, 2012
28 .Dt CK_HT_INIT 3
29 .Sh NAME
30 .Nm ck_ht_init
31 .Nd initialize a hash table
32 .Sh LIBRARY
33 Concurrency Kit (libck, \-lck)
34 .Sh SYNOPSIS
35 .In ck_ht.h
36 .Ft typedef void
37 .Fn ck_ht_hash_cb_t "ck_ht_hash_t *h" "const void *key" "size_t key_length" "uint64_t seed"
38 .Ft bool
39 .Fn ck_ht_init "ck_ht_t *ht" "enum ck_ht_mode mode" "ck_ht_hash_cb_t *hash_function" "struct ck_malloc *allocator" "uint64_t capacity" "uint64_t seed"
40 .Sh DESCRIPTION
41 The
42 .Fn ck_ht_init
43 function initializes the hash table pointed to by the
44 .Fa ht
45 pointer.
46 .Pp
47 The argument
48 .Fa mode
49 specifies the type of key-value pairs to be stored in the
50 hash table. The value of
51 .Fa mode
52 may be one of:
53 .Bl -tag -width indent
54 .It CK_HT_MODE_BYTESTRING
55 The hash table is meant to store key-value pointers where
56 key is a region of memory that is up to 65536 bytes long.
57 This pointer will be dereferenced during hash table operations
58 for key comparison. Entries of this hash table are expected
59 to be interacted with using the
60 .Xr ck_ht_entry_empty 3 ,
61 .Xr ck_ht_entry_key 3 ,
62 .Xr ck_ht_entry_key_length 3 ,
63 .Xr ck_ht_entry_value 3 ,
64 and
65 .Xr ck_ht_entry_set 3
66 functions. Attempting a hash table operation with a key of value
67 NULL or (void *)UINTPTR_MAX will result in undefined behavior.
68 .It CK_HT_MODE_DIRECT
69 The hash table is meant to store key-value pointers where
70 the key is of fixed width field compatible with the
71 .Vt uintptr_t
72 type. The key will be directly compared with other keys for
73 equality. Entries of this hash table are expected to be interacted
74 with using the
75 .Xr ck_ht_entry_empty 3 ,
76 .Xr ck_ht_entry_key_direct 3 ,
77 .Xr ck_ht_entry_value_direct 3
78 and
79 .Xr ck_ht_entry_set_direct 3
80 functions. Attempting a hash table operation with a key of value of 0 or
81 UINTPTR_MAX will result in undefined behavior.
82 .El
83 .Pp
84 In addition to this, the user may bitwise OR the mode flag with
85 CK_HT_WORKLOAD_DELETE to indicate that the hash table will
86 have to handle a delete heavy workload, in which case stronger
87 bounds on latency can be provided at the cost of approximately
88 13% higher memory usage.
89 The argument
90 .Fa hash_function
91 is a pointer to a user-specified hash function. It is optional,
92 if
93 .Dv NULL
94 is specified, then the default hash function implementation will be
95 used (
96 .Xr ck_ht_hash 3 ).
97 A user-specified hash function takes four arguments. The
98 .Fa h
99 argument is a pointer to a hash value object. The hash function
100 is expected to update the
101 .Fa value
102 object of type
103 .Fa uint64_t
104 contained with-in the object pointed to by
105 .Fa h .
106 The
107 .Fa key
108 argument is a pointer to a key, the
109 .Fa key_length
110 argument is the length of the key and the
111 .Fa seed
112 argument is the initial seed associated with the hash table.
113 This initial seed is specified by the user in
114 .Xr ck_ht_init 3 .
115 .Pp
116 The
117 .Fa allocator
118 argument is a pointer to a structure containing
119 .Fa malloc
120 and
121 .Fa free
122 function pointers which respectively define the memory allocation and
123 destruction functions to be used by the hash table being initialized.
124 .Pp
125 The argument
126 .Fa capacity
127 represents the initial number of key-value pairs the hash
128 table is expected to contain. This argument is simply a hint
129 and the underlying implementation is free to allocate more
130 or less memory than necessary to contain the number of entries
131 .Fa capacity
132 specifies.
133 .Pp
134 The argument
135 .Fa seed
136 specifies the initial seed used by the underlying hash function.
137 The user is free to choose a value of their choice.
138 .Pp
139 The hash table is safe to access by multiple readers in the presence
140 of one concurrent writer. Behavior is undefined in the presence of
141 concurrent writers.
142 .Sh RETURN VALUES
143 Upon successful completion
144 .Fn ck_ht_init
145 returns a value of
146 .Dv true
147 and otherwise returns a value of
148 .Dv false
149 to indicate an error.
150 .Sh ERRORS
151 .Bl -tag -width Er
152 .Pp
153 The behavior of
154 .Fn ck_ht_init
155 is undefined if
156 .Fa ht
157 is not a pointer to a
158 .Vt ck_ht_t
159 object.
160 .El
161 .Sh SEE ALSO
162 .Xr ck_ht_stat 3 ,
163 .Xr ck_ht_destroy 3 ,
164 .Xr ck_ht_hash 3 ,
165 .Xr ck_ht_hash_direct 3 ,
166 .Xr ck_ht_set_spmc 3 ,
167 .Xr ck_ht_put_spmc 3 ,
168 .Xr ck_ht_gc 3 ,
169 .Xr ck_ht_get_spmc 3 ,
170 .Xr ck_ht_grow_spmc 3 ,
171 .Xr ck_ht_remove_spmc 3 ,
172 .Xr ck_ht_reset_spmc 3 ,
173 .Xr ck_ht_reset_size_spmc 3 ,
174 .Xr ck_ht_count 3 ,
175 .Xr ck_ht_entry_empty 3 ,
176 .Xr ck_ht_entry_key_set 3 ,
177 .Xr ck_ht_entry_key_set_direct 3 ,
178 .Xr ck_ht_entry_key 3 ,
179 .Xr ck_ht_entry_key_length 3 ,
180 .Xr ck_ht_entry_value 3 ,
181 .Xr ck_ht_entry_set 3 ,
182 .Xr ck_ht_entry_set_direct 3 ,
183 .Xr ck_ht_entry_key_direct 3 ,
184 .Xr ck_ht_entry_value_direct 3 ,
185 .Xr ck_ht_iterator_init 3 ,
186 .Xr ck_ht_next 3
187 .Pp
188 Additional information available at http://concurrencykit.org/