Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. struct std_NameNode {
  2. std_NameNode (*next);
  3. uint32_t len;
  4. char (buf[1]);
  5. };
  6.  
  7. struct tuple4 {
  8. ullong _0;
  9. std_NameNode (*_1);
  10. };
  11.  
  12. struct std_NameMap {
  13. tuple4 (*nodes);
  14. };
  15.  
  16. char (*std_namemap_getn(std_NameMap (*names), char (*buf), size_t len)) {
  17. ullong h = std_hash(buf, len);
  18. ullong i = hget(ullong, (names->nodes), (h));
  19. std_NameNode (*node) = {0};
  20. if ((i) != (std_alen(names->nodes))) {
  21. node = names->nodes[i]._1;
  22. for (std_NameNode (*it) = node; it; it = it->next) {
  23. if (((len) == (it->len)) && ((memcmp(buf, it->buf, len)) == (0))) {
  24. return it->buf;
  25. }
  26. }
  27. }
  28. std_NameNode (*new_node) = malloc(((offsetof(std_NameNode, buf)) + (len)) + (1));
  29. new_node->next = node;
  30. new_node->len = len;
  31. memcpy(new_node->buf, buf, len);
  32. new_node->buf[len] = 0;
  33. hput(tuple4, _0, (names->nodes), (h), (new_node));
  34. return new_node->buf;
  35. }
  36.  
  37. char (*std_namemap_get(std_NameMap (*names), char (*str))) {
  38. return std_namemap_getn(names, str, strlen(str));
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement