The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | /* |
| 17 | * Maintain an expanding set of unique pointer values. The set is |
| 18 | * kept in sorted order. |
| 19 | */ |
| 20 | #ifndef _DALVIK_POINTERSET |
| 21 | #define _DALVIK_POINTERSET |
| 22 | |
| 23 | struct PointerSet; /* private */ |
| 24 | typedef struct PointerSet PointerSet; |
| 25 | |
| 26 | /* |
| 27 | * Allocate a new PointerSet. |
| 28 | * |
| 29 | * Returns NULL on failure. |
| 30 | */ |
| 31 | PointerSet* dvmPointerSetAlloc(int initialSize); |
| 32 | |
| 33 | /* |
| 34 | * Free up a PointerSet. |
| 35 | */ |
| 36 | void dvmPointerSetFree(PointerSet* pSet); |
| 37 | |
| 38 | /* |
| 39 | * Clear the contents of a pointer set. |
| 40 | */ |
| 41 | void dvmPointerSetClear(PointerSet* pSet); |
| 42 | |
| 43 | /* |
| 44 | * Get the number of pointers currently stored in the list. |
| 45 | */ |
| 46 | int dvmPointerSetGetCount(const PointerSet* pSet); |
| 47 | |
| 48 | /* |
| 49 | * Get the Nth entry from the list. |
| 50 | */ |
| 51 | const void* dvmPointerSetGetEntry(const PointerSet* pSet, int i); |
| 52 | |
| 53 | /* |
| 54 | * Insert a new entry into the list. If it already exists, this returns |
| 55 | * without doing anything. |
| 56 | * |
| 57 | * Returns "true" if the pointer was added. |
| 58 | */ |
| 59 | bool dvmPointerSetAddEntry(PointerSet* pSet, const void* ptr); |
| 60 | |
| 61 | /* |
| 62 | * Returns "true" if the element was successfully removed. |
| 63 | */ |
| 64 | bool dvmPointerSetRemoveEntry(PointerSet* pSet, const void* ptr); |
| 65 | |
| 66 | /* |
| 67 | * Returns "true" if the value appears, "false" otherwise. If "pIndex" is |
| 68 | * non-NULL, it will receive the matching index or the index of a nearby |
| 69 | * element. |
| 70 | */ |
| 71 | bool dvmPointerSetHas(const PointerSet* pSet, const void* ptr, int* pIndex); |
| 72 | |
| 73 | /* |
| 74 | * Find an entry in the set. Returns the index, or -1 if not found. |
| 75 | */ |
| 76 | INLINE int dvmPointerSetFind(const PointerSet* pSet, const void* ptr) { |
| 77 | int idx; |
| 78 | if (!dvmPointerSetHas(pSet, ptr, &idx)) |
| 79 | idx = -1; |
| 80 | return idx; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Compute the intersection of the set and the array of pointers passed in. |
| 85 | * |
| 86 | * Any pointer in "pSet" that does not appear in "ptrArray" is removed. |
| 87 | */ |
| 88 | void dvmPointerSetIntersect(PointerSet* pSet, const void** ptrArray, int count); |
| 89 | |
| 90 | /* |
| 91 | * Print the list contents to stdout. For debugging. |
| 92 | */ |
| 93 | void dvmPointerSetDump(const PointerSet* pSet); |
| 94 | |
| 95 | #endif /*_DALVIK_POINTERSET*/ |