MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / ch_ring_get_vnode_idx

Function ch_ring_get_vnode_idx

example/cacheCluster/consistentHash.c:92–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92int ch_ring_get_vnode_idx(const char *const key, const ring_t *const ring) {
93 unsigned int h = ketama_hash(key);
94 int highp = ring->n_point;
95 vnode_t *vnodes = ring->vnodes;
96 int lowp = 0;
97 unsigned int midp;
98 unsigned int midval, midval1;
99 int vnode_idx = -1;
100
101 // divide and conquer array search to find server with next biggest
102 // point after what this key hashes to
103 while (true) {
104 midp = (int)((lowp + highp) / 2);
105
106 if (midp == ring->n_point) {
107 vnode_idx = 0;
108 return vnode_idx;
109 }
110
111 midval = vnodes[midp].point;
112 midval1 = midp == 0 ? 0 : vnodes[midp - 1].point;
113
114 if (h <= midval && h > midval1)
115 vnode_idx = midp;
116 else {
117 if (midval < h)
118 lowp = midp + 1;
119 else
120 highp = midp - 1;
121
122 if (lowp > highp) vnode_idx = 0;
123 }
124
125 if (vnode_idx != -1) break;
126 }
127 return vnode_idx;
128}
129
130// vnode_t *ch_ring_get_server(const char *const key, const ring_t *const ring)
131// {

Callers 4

ch_ring_get_serverFunction · 0.85
ch_ring_get_serversFunction · 0.85

Calls 1

ketama_hashFunction · 0.85

Tested by

no test coverage detected