2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * Maintain an expanding set of unique pointer values. The set is
18 * kept in sorted order.
20 #ifndef _DALVIK_POINTERSET
21 #define _DALVIK_POINTERSET
27 struct PointerSet; /* private */
28 typedef struct PointerSet PointerSet;
31 * Allocate a new PointerSet.
33 * Returns NULL on failure.
35 PointerSet* dvmPointerSetAlloc(int initialSize);
38 * Free up a PointerSet.
40 void dvmPointerSetFree(PointerSet* pSet);
43 * Clear the contents of a pointer set.
45 void dvmPointerSetClear(PointerSet* pSet);
48 * Get the number of pointers currently stored in the list.
50 int dvmPointerSetGetCount(const PointerSet* pSet);
53 * Get the Nth entry from the list.
55 const void* dvmPointerSetGetEntry(const PointerSet* pSet, int i);
58 * Insert a new entry into the list. If it already exists, this returns
59 * without doing anything.
61 * Returns "true" if the pointer was added.
63 bool dvmPointerSetAddEntry(PointerSet* pSet, const void* ptr);
66 * Returns "true" if the element was successfully removed.
68 bool dvmPointerSetRemoveEntry(PointerSet* pSet, const void* ptr);
71 * Returns "true" if the value appears, "false" otherwise. If "pIndex" is
72 * non-NULL, it will receive the matching index or the index of a nearby
75 bool dvmPointerSetHas(const PointerSet* pSet, const void* ptr, int* pIndex);
78 * Find an entry in the set. Returns the index, or -1 if not found.
80 INLINE int dvmPointerSetFind(const PointerSet* pSet, const void* ptr) {
82 if (!dvmPointerSetHas(pSet, ptr, &idx))
88 * Compute the intersection of the set and the array of pointers passed in.
90 * Any pointer in "pSet" that does not appear in "ptrArray" is removed.
92 void dvmPointerSetIntersect(PointerSet* pSet, const void** ptrArray, int count);
95 * Print the list contents to stdout. For debugging.
97 void dvmPointerSetDump(const PointerSet* pSet);
103 #endif /*_DALVIK_POINTERSET*/