Debian Codegraph @

doc/ck_hs_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 September 17, 2012
28 .Dt CK_HS_INIT 3
29 .Sh NAME
30 .Nm ck_hs_init
31 .Nd initialize a hash set
32 .Sh LIBRARY
33 Concurrency Kit (libck, \-lck)
34 .Sh SYNOPSIS
35 .In ck_hs.h
36 .Ft typedef unsigned long
37 .Fn ck_hs_hash_cb_t "const void *key" "unsigned long seed"
38 .Ft typedef bool
39 .Fn ck_hs_compare_cb_t "const void *c1" "const void *c2"
40 .Ft bool
41 .Fn ck_hs_init "ck_hs_t *hs" "unsigned int mode" "ck_hs_hash_cb_t *hash_function" "ck_hs_compare_cb_t *compare" "struct ck_malloc *allocator" "unsigned long capacity" "unsigned long seed"
42 .Sh DESCRIPTION
43 The
44 .Fn ck_hs_init
45 function initializes the hash set pointed to by the
46 .Fa hs
47 pointer.
48 .Pp
49 The argument
50 .Fa mode
51 specifies the type of key-value pairs to be stored in the
52 hash set as well as the expected concurrent access model.
53 The value of
54 .Fa mode
55 consists of a bitfield of one of the following:
56 .Bl -tag -width indent
57 .It CK_HS_MODE_OBJECT
58 The hash set is meant to store pointers to objects. This provides
59 a hint that only CK_MD_VMA_BITS are necessary to encode the key
60 argument. Any unused pointer bits are leveraged for internal
61 optimizations.
62 .It CK_HS_MODE_DIRECT
63 The hash set is meant to directly store key values and that all
64 bits of the key are used to encode values.
65 .El
66 .Pp
67 The concurrent access model is specified by:
68 .Bl -tag -width indent
69 .It CK_HS_MODE_SPMC
70 The hash set should allow for concurrent readers in the
71 presence of a single writer.
72 .It CK_HS_MODE_MPMC
73 The hash set should allow for concurrent readers in the
74 presence of concurrent writers. This is currently unsupported.
75 .El
76 .Pp
77 The developer is free to specify additional workload hints.
78 These hints are one of:
79 .Bl -tag -width indent
80 .It CK_HS_MODE_DELETE
81 The hash set is expected to have a delete-heavy workload.
82 At the cost of approximately 13% increased memory usage,
83 allow for stronger per-slot probe bounds to combat the
84 effects of tombstone accumulation.
85 .El
86 .Pp
87 The argument
88 .Fa hash_function
89 is a mandatory pointer to a user-specified hash function.
90 A user-specified hash function takes two arguments. The
91 .Fa key
92 argument is a pointer to a key. The
93 .Fa seed
94 argument is the initial seed associated with the hash set.
95 This initial seed is specified by the user in
96 .Xr ck_hs_init 3 .
97 .Pp
98 The
99 .Fa compare
100 argument is an optional pointer to a user-specified
101 key comparison function. If NULL is specified in this
102 argument, then pointer equality will be used to determine
103 key equality. A user-specified comparison function takes
104 two arguments representing pointers to the objects being
105 compared for equality. It is expected to return true
106 if the keys are of equal value and false otherwise.
107 .Pp
108 The
109 .Fa allocator
110 argument is a pointer to a structure containing
111 .Fa malloc
112 and
113 .Fa free
114 function pointers which respectively define the memory allocation and
115 destruction functions to be used by the hash set being initialized.
116 .Pp
117 The argument
118 .Fa capacity
119 represents the initial number of keys the hash
120 set is expected to contain. This argument is simply a hint
121 and the underlying implementation is free to allocate more
122 or less memory than necessary to contain the number of entries
123 .Fa capacity
124 specifies.
125 .Pp
126 The argument
127 .Fa seed
128 specifies the initial seed used by the underlying hash function.
129 The user is free to choose a value of their choice.
130 .Sh RETURN VALUES
131 Upon successful completion
132 .Fn ck_hs_init
133 returns a value of
134 .Dv true
135 and otherwise returns a value of
136 .Dv false
137 to indicate an error.
138 .Sh ERRORS
139 .Bl -tag -width Er
140 .Pp
141 The behavior of
142 .Fn ck_hs_init
143 is undefined if
144 .Fa hs
145 is not a pointer to a
146 .Vt ck_hs_t
147 object.
148 .El
149 .Sh SEE ALSO
150 .Xr ck_hs_move 3 ,
151 .Xr ck_hs_destroy 3 ,
152 .Xr CK_HS_HASH 3 ,
153 .Xr ck_hs_iterator_init 3 ,
154 .Xr ck_hs_next 3 ,
155 .Xr ck_hs_get 3 ,
156 .Xr ck_hs_put 3 ,
157 .Xr ck_hs_put_unique 3 ,
158 .Xr ck_hs_set 3 ,
159 .Xr ck_hs_fas 3 ,
160 .Xr ck_hs_remove 3 ,
161 .Xr ck_hs_grow 3 ,
162 .Xr ck_hs_rebuild 3 ,
163 .Xr ck_hs_gc 3 ,
164 .Xr ck_hs_count 3 ,
165 .Xr ck_hs_reset 3 ,
166 .Xr ck_hs_reset_size 3 ,
167 .Xr ck_hs_stat 3
168 .Pp
169 Additional information available at http://concurrencykit.org/