comparison tern.c @ 2207:de3d20e58555

Mostly fix label sorting post-refactor
author Michael Pavone <pavone@retrodev.com>
date Sat, 27 Aug 2022 17:35:28 -0700
parents 193b804c9845
children 8483c685cf03
comparison
equal deleted inserted replaced
2206:4c265d2f6c88 2207:de3d20e58555
291 tern_foreach_int(head, fun, data, key, 0); 291 tern_foreach_int(head, fun, data, key, 0);
292 } 292 }
293 293
294 char * tern_int_key(uint32_t key, char * buf) 294 char * tern_int_key(uint32_t key, char * buf)
295 { 295 {
296 char * cur = buf; 296
297 int len = 0;
298 uint32_t tmp = key;
299 while (tmp)
300 {
301 tmp >>= 7;
302 ++len;
303 }
304 buf[len] = 0;
305 char * cur = buf + len - 1;
297 while (key) 306 while (key)
298 { 307 {
299 *(cur++) = (key & 0x7F) + 1; 308 *(cur--) = (key & 0x7F) + 1;
300 key >>= 7; 309 key >>= 7;
301 } 310 }
302 *cur = 0; 311 return buf;
312 }
313
314 char * tern_sortable_int_key(uint32_t key, char * buf)
315 {
316 buf[MAX_INT_KEY_SIZE - 1] = 0;
317 char * cur = buf + MAX_INT_KEY_SIZE - 2;
318 while (cur >= buf)
319 {
320 *(cur--) = (key & 0x7F) + 1;
321 key >>= 7;
322 }
303 return buf; 323 return buf;
304 } 324 }
305 325
306 void tern_free(tern_node *head) 326 void tern_free(tern_node *head)
307 { 327 {