~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/blenlib/intern/smallhash.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 *
41
41
 * note: these have the SMHASH suffix because we may want to make them public.
42
42
 */
43
 
#define SMHASH_CELL_UNUSED      ((void *)0x7FFFFFFF)
44
 
#define SMHASH_CELL_FREE        ((void *)0x7FFFFFFD)
45
 
 
46
 
#define SMHASH_NONZERO(n) ((n) + !(n))
47
 
#define SMHASH_NEXT(h, hoff) ABS(((h) + ((hoff = SMHASH_NONZERO(hoff * 2) + 1), hoff)))
 
43
#define SMHASH_CELL_UNUSED  ((void *)0x7FFFFFFF)
 
44
#define SMHASH_CELL_FREE    ((void *)0x7FFFFFFD)
 
45
 
 
46
BLI_INLINE int smhash_nonzero(const int n)
 
47
{
 
48
        return n + !n;
 
49
}
 
50
 
 
51
BLI_INLINE int smhash_abs_i(const int n)
 
52
{
 
53
        return (n > 0) ? n : -n;
 
54
}
 
55
 
 
56
/* typically this re-assigns 'h' */
 
57
#define SMHASH_NEXT(h, hoff)  ( \
 
58
        CHECK_TYPE_INLINE(&(h),    int), \
 
59
        CHECK_TYPE_INLINE(&(hoff), int), \
 
60
        smhash_abs_i((h) + (((hoff) = smhash_nonzero((hoff) * 2) + 1), (hoff))) \
 
61
        )
48
62
 
49
63
extern unsigned int hashsizes[];
50
64
 
80
94
 
81
95
void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
82
96
{
83
 
        int h, hoff=1;
 
97
        int h, hoff = 1;
84
98
 
85
99
        if (hash->size < hash->used * 3) {
86
100
                int newsize = hashsizes[++hash->curhash];
103
117
                        hash->table[i].val = SMHASH_CELL_FREE;
104
118
                }
105
119
 
106
 
                for (i = 0; i<hashsizes[hash->curhash - 1]; i++) {
 
120
                for (i = 0; i < hashsizes[hash->curhash - 1]; i++) {
107
121
                        if (ELEM(tmp[i].val, SMHASH_CELL_UNUSED, SMHASH_CELL_FREE)) {
108
122
                                continue;
109
123
                        }
141
155
 
142
156
void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
143
157
{
144
 
        int h, hoff=1;
 
158
        int h, hoff = 1;
145
159
 
146
160
        h = ABS((int)key);
147
161
 
162
176
 
163
177
void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
164
178
{
165
 
        int h, hoff=1;
 
179
        int h, hoff = 1;
166
180
        void *v;
167
181
 
168
182
        h = ABS((int)key);
193
207
int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key)
194
208
{
195
209
        int h = ABS((int)key);
196
 
        int hoff =1;
 
210
        int hoff = 1;
197
211
 
198
212
        if (hash->table == NULL) {
199
213
                return 0;
251
265
#if 0
252
266
void BLI_smallhash_print(SmallHash *hash)
253
267
{
254
 
        int i, linecol=79, c=0;
 
268
        int i, linecol = 79, c = 0;
255
269
 
256
270
        printf("{");
257
 
        for (i=0; i<hash->size; i++) {
 
271
        for (i = 0; i < hash->size; i++) {
258
272
                if (hash->table[i].val == SMHASH_CELL_UNUSED) {
259
273
                        printf("--u-");
260
274
                }
261
275
                else if (hash->table[i].val == SMHASH_CELL_FREE) {
262
276
                        printf("--f-");
263
277
                }
264
 
                else    {
 
278
                else {
265
279
                        printf("%2x", (unsigned int)hash->table[i].key);
266
280
                }
267
281
 
268
 
                if (i != hash->size-1)
 
282
                if (i != hash->size - 1)
269
283
                        printf(", ");
270
284
 
271
285
                c += 6;