docs: libhashkit
[awesomized/libmemcached] / docs / source / libhashkit / hashkit_create.rst
1 Creating a hashkit structure
2 ============================
3
4 SYNOPSIS
5 --------
6
7 #include <libhashkit-|libhashkit_version|/hashkit.h>
8 Compile and link with -lhashkit
9
10 .. type:: struct hashkit_st hashkit_st
11
12 .. function:: hashkit_st *hashkit_create(hashkit_st *hash)
13
14 :param hash: memory address of a `hashkit_st` struct;
15 if a nullptr is passed, the struct will be dynamically allocated by libhashkit
16 :returns: pointer to initialized `hashkit_st` structure
17
18 .. function:: hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *ptr)
19
20 :param destination: memory address of a `hashkit_st` struct;
21 if a nullptr is passed, the struct will be dynamically allocated by libhashkit
22 :param ptr: pointer of the `hashkit_st` struct to copy
23 :returns: pointer to a `hashkit_st` structure (`destination`, if not nullptr), initialized from `ptr`
24
25 .. function:: void hashkit_free(hashkit_st *hash)
26
27 :param hash: pointer to an initialized `hashkit_st` struct
28
29 .. function:: bool hashkit_is_allocated(const hashkit_st *hash)
30
31 :param hash: pointer to an initialized `hashkit_st` struct
32 :returns: bool, whether the `hash` struct was dynamically allocated
33
34 DESCRIPTION
35 -----------
36
37 The `hashkit_create` function initializes a hashkit object for use. If you pass
38 a nullptr argument for hash, then the memory for the object is allocated. If you
39 specify a pre-allocated piece of memory, that is initialized for use.
40
41 The `hashkit_clone` function initializes a hashkit object much like
42 `hashkit_create`, but instead of using default settings it will use the settings
43 of the ptr hashkit object.
44
45 The `hashkit_free` frees any resources being consumed by the hashkit objects
46 that were initialized with `hashkit_create` or `hashkit_clone`.
47
48 The `hashkit_is_allocated` reports whether the memory was allocated for a hashkit
49 object.
50
51 RETURN VALUE
52 ------------
53
54 `hashkit_create` and `hashkit_clone` will return nullptr on failure or pointer
55 to `hashkit_st` on success.
56
57 `hashkit_is_allocated` returns true if the memory for the hashkit object was
58 allocated inside of `hashkit_create` or `hashkit_clone`, otherwise it is false
59 and was user-supplied memory.
60
61 SEE ALSO
62 --------
63
64 .. only:: man
65
66 :manpage:`libhashkit(3)`
67 :manpage:`hashkit_value(3)`
68 :manpage:`hashkit_function3)`
69
70 .. only:: html
71
72 * :doc:`../libhashkit`
73 * :doc:`hashkit_value`
74 * :doc:`hashkit_function`