Debian Codegraph @

src/common/bfind.c

raw symbols SCIP
1
2 /*
3 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
4 * All Rights Reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Authors:
21 * Lukas Kuklinek <[email protected]>
22 */
23
24 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
25 #include <config.h>cxx . . $ `<file>/build/config.h`/
26 #endif
27
28 #include <stddef.h>
29 #ifdef OS_WINDOWS
30 #include <io.h>
31 #else
32 #include <unistd.h>
33 #endif
34 #include <stdint.h>
35 #include <assert.h>
36
37 #include "bfind.h"cxx . . $ `<file>/src/common/bfind.h`/
38
39 void *oscap_bfindcxx . . $ oscap_bfind(55e9dbee426f048c).(void *ptr, size_tcxx . . $ size_t# nmemb, size_tcxx . . $ size_t# size, void *key, int cmpfn(void *, void *))
40 {
41 size_tcxx . . $ size_t# w, s;
42 int cmp;
43 uint8_tcxx . . $ uint8_t# *p;
44
45 w = nmemb;
46 s = 0;
47 p = (uint8_tcxx . . $ uint8_t# *) ptr;
48
49 while (w > 0) {
50 cmp = cmpfn(key, p + (size * (s + w / 2)));
51 if (cmp > 0) {
52 s += w / 2 + 1;
53 w = w - w / 2 - 1;
54 } else if (cmp < 0) {
55 w = w / 2;
56 } else {
57 return ((void *)(p + (size * (s + w / 2))));
58 }
59 }
60
61 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
62 }
63
64 int32_tcxx . . $ int32_t# oscap_bfind_icxx . . $ oscap_bfind_i(1f6e428efd4168b9).(void *ptr, size_tcxx . . $ size_t# nmemb, size_tcxx . . $ size_t# size, void *key, int cmpfn(void *, void *), size_tcxx . . $ size_t# *save)
65 {
66 size_tcxx . . $ size_t# w, s;
67 int cmp;
68 uint8_tcxx . . $ uint8_t# *p;
69
70 w = nmemb;
71 s = 0;
72 p = (uint8_tcxx . . $ uint8_t# *) ptr;
73
74 while (w > 0) {
75 cmp = cmpfn(key, p + (size * (s + w / 2)));
76 if (cmp > 0) {
77 s += w / 2 + 1;
78 w = w - w / 2 - 1;
79 } else if (cmp < 0) {
80 w = w / 2;
81 } else {
82 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!((s + w / 2) <= INT32_MAX);
83 return ((int32_tcxx . . $ int32_t#) (s + w / 2));
84 }
85 }
86
87 if (save != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
88 *save = s;
89
90 return INT32_Ccxx . . $ `<external>/3415975807581488833/stdint.h:239:10`!(-1);
91 }