Debian Codegraph @

doc/ck_rhs_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_RHS_INIT 3
29 .Sh NAME
30 .Nm ck_rhs_init
31 .Nd initialize a hash set
32 .Sh LIBRARY
33 Concurrency Kit (libck, \-lck)
34 .Sh SYNOPSIS
35 .In ck_rhs.h
36 .Ft typedef unsigned long
37 .Fn ck_rhs_hash_cb_t "const void *key" "unsigned long seed"
38 .Ft typedef bool
39 .Fn ck_rhs_compare_cb_t "const void *c1" "const void *c2"
40 .Ft bool
41 .Fn ck_rhs_init "ck_rhs_t *hs" "unsigned int mode" "ck_rhs_hash_cb_t *hash_function" "ck_rhs_compare_cb_t *compare" "struct ck_malloc *allocator" "unsigned long capacity" "unsigned long seed"
42 .Sh DESCRIPTION
43 The
44 .Fn ck_rhs_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_RHS_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_RHS_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 .It CK_RHS_MODE_READ_MOSTLY
66 Optimize read operations over put/delete.
67 .El
68 .Pp
69 The concurrent access model is specified by:
70 .Bl -tag -width indent
71 .It CK_RHS_MODE_SPMC
72 The hash set should allow for concurrent readers in the
73 presence of a single writer.
74 .It CK_RHS_MODE_MPMC
75 The hash set should allow for concurrent readers in the
76 presence of concurrent writers. This is currently unsupported.
77 .El
78 .Pp
79 The developer is free to specify additional workload hints.
80 These hints are one of:
81 .Bl -tag -width indent
82 .El
83 .Pp
84 The argument
85 .Fa hash_function
86 is a mandatory pointer to a user-specified hash function.
87 A user-specified hash function takes two arguments. The
88 .Fa key
89 argument is a pointer to a key. The
90 .Fa seed
91 argument is the initial seed associated with the hash set.
92 This initial seed is specified by the user in
93 .Xr ck_rhs_init 3 .
94 .Pp
95 The
96 .Fa compare
97 argument is an optional pointer to a user-specified
98 key comparison function. If NULL is specified in this
99 argument, then pointer equality will be used to determine
100 key equality. A user-specified comparison function takes
101 two arguments representing pointers to the objects being
102 compared for equality. It is expected to return true
103 if the keys are of equal value and false otherwise.
104 .Pp
105 The
106 .Fa allocator
107 argument is a pointer to a structure containing
108 .Fa malloc
109 and
110 .Fa free
111 function pointers which respectively define the memory allocation and
112 destruction functions to be used by the hash set being initialized.
113 .Pp
114 The argument
115 .Fa capacity
116 represents the initial number of keys the hash
117 set is expected to contain. This argument is simply a hint
118 and the underlying implementation is free to allocate more
119 or less memory than necessary to contain the number of entries
120 .Fa capacity
121 specifies.
122 .Pp
123 The argument
124 .Fa seed
125 specifies the initial seed used by the underlying hash function.
126 The user is free to choose a value of their choice.
127 .Sh RETURN VALUES
128 Upon successful completion
129 .Fn ck_rhs_init
130 returns a value of
131 .Dv true
132 and otherwise returns a value of
133 .Dv false
134 to indicate an error.
135 .Sh ERRORS
136 .Bl -tag -width Er
137 .Pp
138 The behavior of
139 .Fn ck_rhs_init
140 is undefined if
141 .Fa hs
142 is not a pointer to a
143 .Vt ck_rhs_t
144 object.
145 .El
146 .Sh SEE ALSO
147 .Xr ck_rhs_move 3 ,
148 .Xr ck_rhs_destroy 3 ,
149 .Xr CK_RHS_HASH 3 ,
150 .Xr ck_rhs_iterator_init 3 ,
151 .Xr ck_rhs_next 3 ,
152 .Xr ck_rhs_get 3 ,
153 .Xr ck_rhs_put 3 ,
154 .Xr ck_rhs_put_unique 3 ,
155 .Xr ck_rhs_set 3 ,
156 .Xr ck_rhs_fas 3 ,
157 .Xr ck_rhs_remove 3 ,
158 .Xr ck_rhs_grow 3 ,
159 .Xr ck_rhs_rebuild 3 ,
160 .Xr ck_rhs_gc 3 ,
161 .Xr ck_rhs_count 3 ,
162 .Xr ck_rhs_reset 3 ,
163 .Xr ck_rhs_reset_size 3 ,
164 .Xr ck_rhs_stat 3
165 .Pp
166 Additional information available at http://concurrencykit.org/