2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Hash table to store names.
9 * @author Goetz Lindenmaier
29 /* it's ok to use memcmp here, we check only strings */
30 id_set = new_set(memcmp, 128);
33 ident *new_id_from_chars(const char *str, size_t len)
35 unsigned hash = hash_data((const unsigned char*)str, len);
36 ident *result = (ident*) set_hinsert0(id_set, str, len, hash);
40 ident *new_id_from_str(const char *str)
43 return new_id_from_chars(str, strlen(str));
46 const char *get_id_str(ident *id)
48 struct set_entry *entry = (struct set_entry*) id;
49 return (const char*) entry->dptr;
52 size_t get_id_strlen(ident *id)
54 struct set_entry *entry = (struct set_entry*) id;
58 void finish_ident(void)
64 int id_is_prefix(ident *prefix, ident *id)
66 size_t prefix_len = get_id_strlen(prefix);
67 if (prefix_len > get_id_strlen(id))
69 return 0 == memcmp(get_id_str(prefix), get_id_str(id), prefix_len);
72 int id_is_suffix(ident *suffix, ident *id)
74 size_t suflen = get_id_strlen(suffix);
75 size_t idlen = get_id_strlen(id);
81 part = get_id_str(id);
82 part = part + (idlen - suflen);
84 return 0 == memcmp(get_id_str(suffix), part, suflen);
87 int id_contains_char(ident *id, char c)
89 return strchr(get_id_str(id), c) != NULL;
92 ident *id_unique(const char *tag)
94 static unsigned unique_id = 0;
97 snprintf(buf, sizeof(buf), tag, unique_id);
99 return new_id_from_str(buf);