blob: 94abe7b85b3c55c30ac582208d91925e34ae963f [file] [log] [blame]
Andy McFadden2867f0b2010-12-10 11:08:22 -08001/*
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/*
18 * Miscellaneous utility functions.
19 */
20#ifndef _DALVIK_BITVECTOR
21#define _DALVIK_BITVECTOR
22
23/*
24 * Expanding bitmap, used for tracking resources. Bits are numbered starting
25 * from zero.
26 *
27 * All operations on a BitVector are unsynchronized.
28 */
29typedef struct BitVector {
30 bool expandable; /* expand bitmap if we run out? */
31 int storageSize; /* current size, in 32-bit words */
32 u4* storage;
33} BitVector;
34
35/* allocate a bit vector with enough space to hold "startBits" bits */
36BitVector* dvmAllocBitVector(int startBits, bool expandable);
37void dvmFreeBitVector(BitVector* pBits);
38
39/*
40 * dvmAllocBit always allocates the first possible bit. If we run out of
41 * space in the bitmap, and it's not marked expandable, dvmAllocBit
42 * returns -1.
43 *
44 * dvmSetBit sets the specified bit, expanding the vector if necessary
45 * (and possible).
46 *
47 * dvmIsBitSet returns "true" if the bit is set.
48 */
49int dvmAllocBit(BitVector* pBits);
50bool dvmSetBit(BitVector* pBits, int num);
51void dvmClearBit(BitVector* pBits, int num);
52void dvmClearAllBits(BitVector* pBits);
53bool dvmIsBitSet(const BitVector* pBits, int num);
54
55/* count the number of bits that have been set */
56int dvmCountSetBits(const BitVector* pBits);
57
58/* copy one vector to the other compatible one */
59bool dvmCopyBitVector(BitVector *dest, const BitVector *src);
60
61/*
62 * Intersect two bit vectores and merge the result on top of the pre-existing
63 * value in the dest vector.
64 */
65bool dvmIntersectBitVectors(BitVector *dest, const BitVector *src1,
66 const BitVector *src2);
67
68
69#endif /*_DALVIK_BITVECTOR*/