MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / query

Method query

Data Structures/Trie.cpp:29–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 }
28 }
29 int query(int x, int k) { // number of values s.t. val ^ x < k
30 node* cur = root;
31 int ans = 0;
32 for (int i = B - 1; i >= 0; i--) {
33 if (cur == NULL) break;
34 int b1 = x >> i & 1, b2 = k >> i & 1;
35 if (b2 == 1) {
36 if (cur -> nxt[b1]) ans += cur -> nxt[b1] -> sz;
37 cur = cur -> nxt[!b1];
38 } else cur = cur -> nxt[b1];
39 }
40 return ans;
41 }
42 int get_max(int x) { // returns maximum of val ^ x
43 node* cur = root;
44 int ans = 0;

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected