Menu

[r7]: / trunk / src / A1BitArray.h  Maximize  Restore  History

Download this file

145 lines (122 with data), 4.6 kB

  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
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* A1BitSet.h
* BitArray is a framework that provides a scalable class that uses sparse allocation for
* addressing disjoint bits sets. This is an ideal framework for handling large amounts of
* preferences or as a front end to large data sets that need sparse indexes.
*
* Created by frankcastellucci on 1/3/11.
* Copyright 2011 Axiom:1, Inc. All rights reserved. (mailto:information@axiom1inc.com)
*
* This file is part of BitArray.
* BitArray is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* BitArray 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.
*
* You should have received a copy of the GNU General Public License
* called "COPYING" along with BitArray. If not, see <http://www.gnu.org/licenses/>.
*
*/
#import <Foundation/Foundation.h>
/*
Error management
*/
FOUNDATION_EXPORT NSString *const BitArrayErrorDomain;
enum {
BitArrayUnknownError= 1, // Unknown general error
BitIndexOutOfRange = 100, // Good indication that extents are turned off
UnableToAllocateExtent = 200, // Failure in calloc
UnableToIncreaseExtentControl = 210 // Failure in realloc
};
/*!
@header A1BitArray
@abstract Sparse bit array that supports sparse addressing and extents
@discussion A1BitArray enables the use of large bit blocks. The base array holds 1024 bits
and, using the appropriate initializer, can support default or user defined extents.
*/
@interface A1BitArray : NSObject<NSCopying,NSCoding> {
@private
void *control;
}
#pragma mark -
#pragma mark Initializers
/*!
@method initWithExtentsAllowed
@abstract Initializes bit array to allow automatic extent creation
@discussion Bit arrays initialized with extent support enable the instance to
create a block of bits if you address a location (using clearBit or setBit)
that is not already part of the array. Unlike other array types, these
addresses (bits) do not allocate filler memory to make it contigous with
the base array (sparse).
@result A1BitArray initialzed to support extents
*/
- (id) initWithExtentsAllowed;
/*!
@method initWithExtentSize:
@abstract Initializes bit array to support extents of size extentSizeInBytes
@discussion The default extent size, 128 bytes (1024 bits) may not be the right size
given the use of the instance. The caller may specify the size of the
extents, in bytes. The supplied value is rounded to 64 bytes, so the
minimum block the instance allocates will be 512 bits in size.
@param extentSizeInBytes Number of bytes in extent size
@result A1BitArray iniitialized to support extents of a byte size provided by
the caller, rounded to multiples of 64 bytes.
*/
- (id) initWithExtentSize:(unsigned short) extentSizeInBytes;
#pragma mark -
#pragma mark Accessors
/*!
@method dirty
@abstract Whether the instance has been modified
@discussion For the standard 'init', the dirty flag is set to YES until, if ever,
it is encoded. All clear and set mutators raise the dirty flag as well as creation of
extents.
@result YES if instance has been modified
*/
- (BOOL) dirty;
/*!
@method bytesInBase
@abstract The base array is a fixed block
@result Total bytes in the base array
*/
- (NSUInteger) bytesInBase;
/*!
@method bitsInBase
@abstract The base array is a fixed block
@result Total number of bits in the base array
*/
- (NSUInteger) bitsInBase;
- (BOOL) extentsAllowed;
- (NSUInteger) extentCount;
- (NSUInteger) bytesInExtent;
- (NSUInteger) bitsInExtent;
/*!
@function(bit)
Returns the state of the bit specified in bitIndex
*/
- (BOOL) bit:(NSUInteger) bitIndex error:(NSError **)err;
#pragma mark -
#pragma mark Mutators
/*!
Clears (turns off) the bit specified in bitIndex
*/
- (void) clearBit:(NSUInteger) bitIndex error:(NSError **) err;
/*!
Clears all bits in the base array
*/
- (void) clear;
/*!
Clears all the bits in the extent framing bitIndex
*/
- (void) clearExtentWithBit:(NSUInteger) bitIndex error:(NSError **)err;
/*!
Sets (turns on) the bit specified in bitIndex
*/
- (void) setBit:(NSUInteger) bitIndex error:(NSError **) err;
- (void) set;
- (void) setExtentWithBit:(NSUInteger) bitIndex error:(NSError **)err;
@end