Rizin
unix-like reverse engineering framework and cli tools
ht_up.c
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2016-2018 crowell
2
// SPDX-FileCopyrightText: 2016-2018 pancake <pancake@nopcode.org>
3
// SPDX-FileCopyrightText: 2016-2018 ret2libc <sirmy15@gmail.com>
4
// SPDX-License-Identifier: BSD-3-Clause
5
6
#include "
ht_up.h
"
7
#include "
ht_inc.c
"
8
9
static
HtName_
(Ht) * internal_ht_default_new(
ut32
size
,
ut32
prime_idx,
HT_
(DupValue) valdup,
HT_
(KvFreeFunc) pair_free,
HT_
(CalcSizeV) calcsizeV) {
10
HT_
(Options)
11
opt = {
12
.cmp =
NULL
,
13
.hashfn =
NULL
,
// TODO: use a better hash function for numbers
14
.dupkey =
NULL
,
15
.dupvalue = valdup,
16
.calcsizeK =
NULL
,
17
.calcsizeV = calcsizeV,
18
.freefn = pair_free,
19
.elem_size =
sizeof
(
HT_
(Kv)),
20
};
21
return
internal_ht_new(
size
, prime_idx, &opt);
22
}
23
24
RZ_API
HtName_
(Ht) *
Ht_
(
new
)(
HT_
(DupValue) valdup,
HT_
(KvFreeFunc) pair_free,
HT_
(CalcSizeV) calcsizeV) {
25
return
internal_ht_default_new(
ht_primes_sizes
[0], 0, valdup, pair_free, calcsizeV);
26
}
27
28
// creates a default HtUP that does not dup, nor free the values
29
RZ_API
HtName_
(Ht) *
Ht_
(new0)(void) {
30
return
Ht_
(
new
)(
NULL
,
NULL
,
NULL
);
31
}
32
33
RZ_API
HtName_
(Ht) *
Ht_
(new_size)(
ut32
initial_size,
HT_
(DupValue) valdup,
HT_
(KvFreeFunc) pair_free,
HT_
(CalcSizeV) calcsizeV) {
34
ut32
i
= 0;
35
36
while
(
i
<
S_ARRAY_SIZE
(
ht_primes_sizes
) &&
37
ht_primes_sizes
[
i
] *
LOAD_FACTOR
< initial_size) {
38
i
++;
39
}
40
if
(
i
==
S_ARRAY_SIZE
(
ht_primes_sizes
)) {
41
i
=
UT32_MAX
;
42
}
43
44
ut32
sz =
compute_size
(
i
, (
ut32
)(initial_size * (2 -
LOAD_FACTOR
)));
45
return
internal_ht_default_new(sz,
i
, valdup, pair_free, calcsizeV);
46
}
i
lzma_index ** i
Definition:
index.h:629
RZ_API
#define RZ_API
Definition:
core_plugin_example.c:36
NULL
#define NULL
Definition:
cris-opc.c:27
ut32
uint32_t ut32
Definition:
demangler_util.h:31
ht_inc.c
ht_primes_sizes
static const ut32 ht_primes_sizes[]
Definition:
ht_inc.c:10
compute_size
static ut32 compute_size(ut32 idx, ut32 sz)
Definition:
ht_inc.c:59
LOAD_FACTOR
#define LOAD_FACTOR
Definition:
ht_inc.c:6
S_ARRAY_SIZE
#define S_ARRAY_SIZE(x)
Definition:
ht_inc.c:7
HT_
#define HT_(name)
Definition:
ht_inc.h:45
Ht_
#define Ht_(name)
Definition:
ht_inc.h:44
HtName_
static HtName_(Ht)
Definition:
ht_up.c:9
ht_up.h
size
voidpf void uLong size
Definition:
ioapi.h:138
UT32_MAX
#define UT32_MAX
Definition:
rz_types_base.h:99
librz
util
sdb
src
ht_up.c
Generated by
1.9.1