ref: 1060697b5f0b60a13f90e54eb430b64e5fae1d8d
parent: e1f94f3ec5a341998d926a70dac6442762d5e3b8
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Nov 27 20:40:58 EST 2014
dict: use ints for keys
--- a/dict.c
+++ b/dict.c
@@ -9,10 +9,10 @@
struct dict {
struct iset *map;
char **key;
- long *val;
+ int *val;
int size;
int n;
- long notfound; /* the value returned for missing keys */
+ int notfound; /* the value returned for missing keys */
int level2; /* use two characters for hashing */
int dupkeys; /* duplicate keys if set */
};
@@ -31,7 +31,7 @@
* dupkeys: if nonzero, store a copy of keys inserted via dict_put().
* level2: use two characters for hasing
*/
-struct dict *dict_make(long notfound, int dupkeys, int level2)
+struct dict *dict_make(int notfound, int dupkeys, int level2)
{
struct dict *d = xmalloc(sizeof(*d));
memset(d, 0, sizeof(*d));
@@ -56,7 +56,7 @@
free(d);
}
-void dict_put(struct dict *d, char *key, long val)
+void dict_put(struct dict *d, char *key, int val)
{
int idx;
if (d->n >= d->size)
@@ -90,12 +90,12 @@
return d->key[idx];
}
-long dict_val(struct dict *d, int idx)
+int dict_val(struct dict *d, int idx)
{
return d->val[idx];
}
-long dict_get(struct dict *d, char *key)
+int dict_get(struct dict *d, char *key)
{
int idx = dict_idx(d, key);
return idx >= 0 ? d->val[idx] : d->notfound;
@@ -102,7 +102,7 @@
}
/* match a prefix of key; in the first call, *idx should be -1 */
-long dict_prefix(struct dict *d, char *key, int *pos)
+int dict_prefix(struct dict *d, char *key, int *pos)
{
int *r = iset_get(d->map, DHASH(d, key));
while (r && r[++*pos] >= 0) {
--- a/roff.h
+++ b/roff.h
@@ -122,14 +122,14 @@
int iset_len(struct iset *iset, int key);
/* mapping strings to longs */
-struct dict *dict_make(long notfound, int dupkeys, int level2);
+struct dict *dict_make(int notfound, int dupkeys, int level2);
void dict_free(struct dict *d);
-void dict_put(struct dict *d, char *key, long val);
-long dict_get(struct dict *d, char *key);
+void dict_put(struct dict *d, char *key, int val);
+int dict_get(struct dict *d, char *key);
int dict_idx(struct dict *d, char *key);
char *dict_key(struct dict *d, int idx);
-long dict_val(struct dict *d, int idx);
-long dict_prefix(struct dict *d, char *key, int *idx);
+int dict_val(struct dict *d, int idx);
+int dict_prefix(struct dict *d, char *key, int *idx);
/* device related variables */
extern int dev_res;