aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils/refset.h
blob: 12cc2400f6c568da60da355b83d19273961e5ccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Copyright (C) 2009 The Android Open Source Project
**
** This software is licensed under the terms of the GNU General Public
** License version 2, as published by the Free Software Foundation, and
** may be copied, distributed, and modified under those terms.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
*/
#ifndef _ANDROID_UTILS_REFSET_H
#define _ANDROID_UTILS_REFSET_H

#include <android/utils/vector.h>

/* this implements a set of addresses in memory.
 * NULL cannot be stored in the set.
 */

typedef struct {
    AVECTOR_DECL(void*,buckets);
} ARefSet;

AINLINED void
arefSet_init( ARefSet*  s )
{
    AVECTOR_INIT(s,buckets);
}

AINLINED void
arefSet_done( ARefSet*  s )
{
    AVECTOR_DONE(s,buckets);
}

AINLINED int
arefSet_count( ARefSet*  s )
{
    return (int) AVECTOR_SIZE(s,buckets);
}

extern ABool  arefSet_has( ARefSet*  s, void*  item );
extern void   arefSet_add( ARefSet*  s, void*  item );
extern void   arefSet_del( ARefSet*  s, void*  item );

#define  AREFSET_DELETED ((void*)~(size_t)0)

#define  AREFSET_FOREACH(_set,_item,_statement) \
    do { \
        int  __refset_nn = 0; \
        int  __refset_max = (_set)->max_buckets; \
        for ( ; __refset_nn < __refset_max; __refset_nn++ ) { \
            void*  __refset_item = (_set)->buckets[__refset_nn]; \
            if (__refset_item == NULL || __refset_item == AREFSET_DELETED) \
                continue; \
            void* _item = __refset_item; \
            _statement; \
        } \
    } while (0)

#endif /* _ANDROID_UTILS_REFSET_H */