From 075190b3e34fa330968c4c76ee0f63a4720e63dc Mon Sep 17 00:00:00 2001
From: Luben Karavelov <karavelov@spnet.net>
Date: Sat, 14 Aug 2010 23:49:25 +0300
Subject: [PATCH 2/7] rename hash->bucket_indices to hash->index.
---
include/parrot/hash.h | 10 ++++++----
src/hash.c | 20 ++++++++++----------
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/include/parrot/hash.h b/include/parrot/hash.h
index fe9bfba..c23afa6 100644
a
|
b
|
|
51 | 51 | HashBucket *buckets; |
52 | 52 | |
53 | 53 | /* List of Bucket pointers */ |
54 | | HashBucket **bucket_indices; |
| 54 | HashBucket **index; |
55 | 55 | |
56 | 56 | /* Store for empty buckets */ |
57 | 57 | HashBucket *free_list; |
… |
… |
|
87 | 87 | HashBucket *_bucket = (_hash)->buckets; \ |
88 | 88 | while (_found < _hash->entries){ \ |
89 | 89 | if (_bucket->key){ \ |
90 | | _code \ |
91 | 90 | _found++; \ |
| 91 | { \ |
| 92 | _code \ |
| 93 | } \ |
92 | 94 | } \ |
93 | 95 | _bucket++; \ |
94 | 96 | } \ |
… |
… |
|
98 | 100 | { \ |
99 | 101 | INTVAL _loc; \ |
100 | 102 | for (_loc = (_hash)->mask; _loc >= 0; --_loc) { \ |
101 | | HashBucket *_bucket = (_hash)->bucket_indices[_loc]; \ |
| 103 | HashBucket *_bucket = (_hash)->index[_loc]; \ |
102 | 104 | while (_bucket) { \ |
103 | 105 | _code \ |
104 | 106 | _bucket = _bucket->next; \ |
… |
… |
|
116 | 118 | /* If there is no more buckets */ \ |
117 | 119 | if ((_loc) == (INTVAL)(_hash)->mask+1) \ |
118 | 120 | break; \ |
119 | | (_bucket) = (_hash)->bucket_indices[_loc++]; \ |
| 121 | (_bucket) = (_hash)->index[_loc++]; \ |
120 | 122 | } \ |
121 | 123 | } |
122 | 124 | |
diff --git a/src/hash.c b/src/hash.c
index 968733b..a59b739 100644
a
|
b
|
|
800 | 800 | | --> buckets | | |
801 | 801 | +---+---+---+-+-+-+-+ |
802 | 802 | ^ ^ |
803 | | | old_mem | hash->bucket_indices |
| 803 | | old_mem | hash->index |
804 | 804 | */ |
805 | 805 | |
806 | 806 | /* resize mem */ |
… |
… |
|
821 | 821 | | buckets | old_bi | new_bi | |
822 | 822 | +---+---+---+---+---+---+-+-+-+-+-+-+-+-+ |
823 | 823 | ^ ^ |
824 | | | new_mem | hash->bucket_indices |
| 824 | | new_mem | hash->index |
825 | 825 | */ |
826 | 826 | |
827 | 827 | bs = new_mem; |
… |
… |
|
835 | 835 | mem_sys_memmove(new_bi, old_bi, old_size * sizeof (HashBucket *)); |
836 | 836 | |
837 | 837 | /* update hash data */ |
838 | | hash->bucket_indices = new_bi; |
| 838 | hash->index = new_bi; |
839 | 839 | hash->buckets = bs; |
840 | 840 | hash->mask = new_size - 1; |
841 | 841 | |
… |
… |
|
1033 | 1033 | |
1034 | 1034 | hash->buckets = bp; |
1035 | 1035 | bp += N_BUCKETS(INITIAL_BUCKETS); |
1036 | | hash->bucket_indices = (HashBucket **)bp; |
| 1036 | hash->index = (HashBucket **)bp; |
1037 | 1037 | |
1038 | 1038 | for (i = 0, --bp; i < N_BUCKETS(INITIAL_BUCKETS); ++i, --bp) { |
1039 | 1039 | bp->next = hash->free_list; |
… |
… |
|
1113 | 1113 | UINTVAL i; |
1114 | 1114 | |
1115 | 1115 | for (i = 0; i <= hash->mask; ++i) { |
1116 | | HashBucket *bucket = hash->bucket_indices[i]; |
| 1116 | HashBucket *bucket = hash->index[i]; |
1117 | 1117 | while (bucket) { |
1118 | 1118 | mem_gc_free(interp, bucket->key); |
1119 | 1119 | func(bucket->value); |
… |
… |
|
1238 | 1238 | /* if the fast search didn't work, try the normal hashing search */ |
1239 | 1239 | { |
1240 | 1240 | const UINTVAL hashval = get_hash_val(interp, hash, key); |
1241 | | HashBucket *bucket = hash->bucket_indices[hashval & hash->mask]; |
| 1241 | HashBucket *bucket = hash->index[hashval & hash->mask]; |
1242 | 1242 | const hash_comp_fn compare = hash->compare; |
1243 | 1243 | |
1244 | 1244 | while (bucket) { |
… |
… |
|
1320 | 1320 | { |
1321 | 1321 | ASSERT_ARGS(parrot_hash_put) |
1322 | 1322 | const UINTVAL hashval = get_hash_val(interp, hash, key); |
1323 | | HashBucket *bucket = hash->bucket_indices[hashval & hash->mask]; |
| 1323 | HashBucket *bucket = hash->index[hashval & hash->mask]; |
1324 | 1324 | const hash_comp_fn compare = hash->compare; |
1325 | 1325 | |
1326 | 1326 | /* See if we have an existing value for this key */ |
… |
… |
|
1349 | 1349 | hash->free_list = bucket->next; |
1350 | 1350 | bucket->key = key; |
1351 | 1351 | bucket->value = value; |
1352 | | bucket->next = hash->bucket_indices[hashval & hash->mask]; |
1353 | | hash->bucket_indices[hashval & hash->mask] = bucket; |
| 1352 | bucket->next = hash->index[hashval & hash->mask]; |
| 1353 | hash->index[hashval & hash->mask] = bucket; |
1354 | 1354 | } |
1355 | 1355 | |
1356 | 1356 | return bucket; |
… |
… |
|
1373 | 1373 | { |
1374 | 1374 | ASSERT_ARGS(parrot_hash_delete) |
1375 | 1375 | const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed) & hash->mask; |
1376 | | HashBucket **prev = &hash->bucket_indices[hashval]; |
| 1376 | HashBucket **prev = &hash->index[hashval]; |
1377 | 1377 | if (*prev) { |
1378 | 1378 | const hash_comp_fn compare = hash->compare; |
1379 | 1379 | for (; *prev; prev = &(*prev)->next) { |