OLBitSet Class Reference
[Containers]

A set of bits. More...

#import <ObjectiveLib/BitSet.h>

Inheritance diagram for OLBitSet:

Inheritance graph
[legend]
List of all members.

Public Member Functions

(BOOL) - any
 Test whether any bits are set.
(OLBitSet *) - bitSetFlipped
 Return a flipped copy of this bit set.
(OLBitSet *) - bitSetShiftedLeft:
 Return a left-shifted copy of this bit set.
(OLBitSet *) - bitSetShiftedRight:
 Return a right-shifted copy of this bit set.
(id) - copyWithZone:
 Make a copy of this bit set allocating memory from the given zone.
(unsigned) - count
 Return the number of bits set.
(void) - encodeWithCoder:
 Encode the bit set.
(void) - flip
 Flip all the bits.
(void) - flip:
 Flip a bit.
(BOOL) - isEqual:
 Return whether this bit set is equal to another one.
(void) - logicalAnd:
 Perform a logical "and" operation.
(void) - logicalOr:
 Perform a logical "or" operation.
(void) - logicalXor:
 Perform a logical "xor" operation.
(BOOL) - none
 Test whether no bit is set.
(void) - reset
 Set every bit to zero.
(void) - reset:
 Set a bit to zero.
(void) - set
 Set every bit to one.
(void) - set:
 Set a bit to one.
(void) - shiftLeft:
 Shift the bits to the left.
(void) - shiftRight:
 Shift the bits to the right.
(unsigned) - size
 Return the number of bits in this set.
(BOOL) - test:
 Test a bit.
(char *) - toString
 Return a string describing this bit set.
(void) - writeSelfToStream:
 Write the object to a stream.
Initializers and Deallocators
(void) - dealloc
 Finalize the bit set and deallocate any allocated memory.
(id) - initWithBitSet:
 Initialize the bit set.
(id) - initWithCoder:
 Initialize the bit set.
(id) - initWithObjectInStream:
 Initialize the object.
(id) - initWithSetSize:
 Initialize the bit set.
(id) - initWithString:position:count:
 Initialize the bit set.
(id) - initWithValue:
 Initialize the bit set.

Static Public Member Functions

(id) + bitSetWithBitSet:
 Create and return a new bit set.
(id) + bitSetWithSetSize:
 Create and return a new bit set.
(id) + bitSetWithString:position:count:
 Create and return a new bit set.
(id) + bitSetWithValue:
 Create and return a new bit set.

Protected Attributes

unsigned numberOfBits
 The number of bits.
unsigned numberOfWords
 The number of words in the allocated range.
uint32_t * words
 The allocated memory for the bit set.

Detailed Description

A set of bits.

A bit set is a collection of bits the size of which cannot be changed. Operations typical for bits are provided, which include flipping, testing and performing logical operations on them. A bit set is very similar to a boolean vector except that it does not pretend to be a true container. It does not provide iterators, and therefore cannot be used with generic algorithms.

See also:
OLBoolVector


Member Function Documentation

- (BOOL) any  

Test whether any bits are set.

Returns:
YES if any bits are set, NO otherwise

- (OLBitSet*) bitSetFlipped  

Return a flipped copy of this bit set.

A bit set is created with the same size as this one, and all bits are the opposite of the corresponding bits in this bit set.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Returns:
a bit set with all bits flipped relative to this one

- (OLBitSet*) bitSetShiftedLeft: (unsigned)  count  

Return a left-shifted copy of this bit set.

A bit set is created with the same size as this one, and the bits are set as if all the bits in this set had been shifted to the left by count. The count most significant bits in the returned set will be set to zero.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
count the number of bits to shift to the left
Returns:
a copy of this bit set that is shifted to the left by count relative to this one

- (OLBitSet*) bitSetShiftedRight: (unsigned)  count  

Return a right-shifted copy of this bit set.

A bit set is created with the same size as this one, and the bits are set as if all the bits in this set had been shifted to the right by count. The count least significant bits in the returned set will be set to zero.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
count the number of bits to shift to the right
Returns:
a copy of this bit set that is shifted to the right by count relative to this one

+ (id) bitSetWithBitSet: (OLBitSet *)  bitSet  

Create and return a new bit set.

The new bit set is initialized with the contents of bitSet.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
bitSet the bit set with which to initialize the new one
Returns:
a new bit set

+ (id) bitSetWithSetSize: (unsigned)  bits  

Create and return a new bit set.

The new bit is allocated to contain bits bits, and initially all bits are set to zero.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
bits the number of bits that the new set should be able to address
Returns:
a new bit set

+ (id) bitSetWithString: (const char *)  str
position: (unsigned)  pos
count: (unsigned)  count 

Create and return a new bit set.

The new bit set is initialized with the contents of str. Working from left to right starting at the position pos in the string, each character is checked. For every index in the bit set starting at zero, if the string's character is '1', then the bit at that index is set, otherwise it remains unset. For example, the string "0101" will produce a bit set of size four where the second and fourth indexes are set and first and third are unset.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
str the string with which to initialize the new bit set
pos the position in the string from which to start processing
count the number of positions in the string that will be considered
Returns:
a new bit set

+ (id) bitSetWithValue: (uint32_t)  val  

Create and return a new bit set.

The new bit set is initialized using a uint32_t value. That is, the size of the bit set will be 32 bits and all the bits set in val will be set in the bit set.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
val the uint32_t with which to initialize the bit set
Returns:
a new bit set

- (id) copyWithZone: (NSZone *)  zone  

Make a copy of this bit set allocating memory from the given zone.

Parameters:
zone the zone from which to allocate memory
Returns:
the copy

- (unsigned) count  

Return the number of bits set.

Any bit in the bit set is that is not zero is added to the total count which is returned.

Returns:
the number of bits set

- (void) dealloc  

Finalize the bit set and deallocate any allocated memory.

- (void) encodeWithCoder: (NSCoder *)  encoder  

Encode the bit set.

The bit set is saved to an archive using encoder. The bit set will be retrieved from the archive using the initializer initWithCoder:.

Parameters:
encoder the coder which will save the bit set to the archive

- (void) flip  

Flip all the bits.

The bit set is tranformed into a bit set that is the logical opposite of this one. All bits that were zero will be one and vice versa.

- (void) flip: (unsigned)  pos  

Flip a bit.

The bit at index pos is flipped. That is, if it was one it will be zero and vice versa.

Note:
The range of the bit set is not checked prior to performing this operation. If an index is given that is greater than or equal to the size of this bit set, then the results are undefined.
Parameters:
pos the bit position to flip

- (id) initWithBitSet: (OLBitSet *)  bitSet  

Initialize the bit set.

All of the bits are copied from bitSet.

Parameters:
bitSet the bit set with which to initialize this one
Returns:
a reference to this bit set

- (id) initWithCoder: (NSCoder *)  decoder  

Initialize the bit set.

Creates a new bit set from an archive and returns it.

Postcondition:
The bit set returned will be identical to the bit set saved to the archive using the encodeWithCoder: message.
Parameters:
decoder the coder which will decode the archived bit set
Returns:
a reference to this bit set

- (id) initWithObjectInStream: (OLObjectInStream *)  stream  

Initialize the object.

Each instance variable is read from stream and all other initialization is performed.

Parameters:
stream the stream from which to read
Returns:
a reference to this object

Reimplemented from < OLStreamable >.

- (id) initWithSetSize: (unsigned)  bits  

Initialize the bit set.

Enough memory is allocated to account for bits bits, and initially all bits are set to zero.

Parameters:
bits the number of bits that this set should be able to address
Returns:
a reference to this bit set

- (id) initWithString: (const char *)  str
position: (unsigned)  pos
count: (unsigned)  count 

Initialize the bit set.

A special string is used to initialize the bit set. Working from left to right starting at the position pos in the string, each character is checked. For every index in the bit set starting at zero, if the string's character is '1', then the bit at that index is set, otherwise it remains unset. For example, the string "0101" will produce a bit set of size four where the second and fourth indexes are set and first and third are unset.

Parameters:
str the string with which to initialize the bit set
pos the position in the string from which to start processing
count the number of positions in the string that will be considered
Returns:
a reference to this bit set

- (id) initWithValue: (uint32_t)  val  

Initialize the bit set.

The bit set is initialized using a uint32_t value. That is, the size of the bit set will be the size of a uint32_t (that's 32 bits, if you're a little slow), and all the bits set in val will be set in the bit set.

Parameters:
val the uint32_t with which to initialize the bit set
Returns:
a reference to this bit set

- (BOOL) isEqual: (id)  object  

Return whether this bit set is equal to another one.

The bit sets are considered equal if they have the same size and if they share the same set bits.

Parameters:
object the object to test
Returns:
YES if object is equal to this bit set, NO otherwise

- (void) logicalAnd: (OLBitSet *)  right  

Perform a logical "and" operation.

If bits in both sets are set at the same position, then the bit in this set will remain set, otherwise it will be unset. The two bit sets do not have to be the same size. The number of bits used in the operation is the smaller of the sizes of the two bit sets. All other bits are ignored.

Parameters:
right the bit set with which to "and" this one

- (void) logicalOr: (OLBitSet *)  right  

Perform a logical "or" operation.

If either bit in both sets is set at the same position, then the bit in this set will be set, otherwise it will be unset. The two bit sets do not have to be the same size. The number of bits used in the operation is the smaller of the sizes of the two bit sets. All other bits are ignored.

Parameters:
right the bit set with which to "and" this one

- (void) logicalXor: (OLBitSet *)  right  

Perform a logical "xor" operation.

If either bit in both sets is set at the same position but not both bits, then the bit in this set will be set, otherwise it will be unset. The two bit sets do not have to be the same size. The number of bits used in the operation is the smaller of the sizes of the two bit sets. All other bits are ignored.

Parameters:
right the bit set with which to "and" this one

- (BOOL) none  

Test whether no bit is set.

Returns:
YES if no bit is set, NO otherwise

- (void) reset  

Set every bit to zero.

- (void) reset: (unsigned)  pos  

Set a bit to zero.

The bit at index pos will be set to zero.

Note:
The range of the bit set is not checked prior to performing this operation. If an index is given that is greater than or equal to the size of this bit set, then the results are undefined.
Parameters:
pos the bit position to reset

- (void) set  

Set every bit to one.

- (void) set: (unsigned)  pos  

Set a bit to one.

The bit at index pos will be set to one.

Note:
The range of the bit set is not checked prior to performing this operation. If an index is given that is greater than or equal to the size of this bit set, then the results are undefined.
Parameters:
pos the bit position to set

- (void) shiftLeft: (unsigned)  count  

Shift the bits to the left.

The bits will be shifted to the left by count positions. The most significant count bits will be set to zero.

Parameters:
count the number of positions by which to shift the bits

- (void) shiftRight: (unsigned)  count  

Shift the bits to the right.

The bits will be shifted to the right by count positions. The least significant count bits will be set to zero.

Parameters:
count the number of positions by which to shift the bits

- (unsigned) size  

Return the number of bits in this set.

Returns:
the number of bits

- (BOOL) test: (unsigned)  pos  

Test a bit.

The bit at index pos is tested.

Note:
The range of the bit set is not checked prior to performing this operation. If an index is given that is greater than or equal to the size of this bit set, then the results are undefined.
Parameters:
pos the bit position to reset

- (char*) toString  

Return a string describing this bit set.

A null-terminated string is returned in which each character is set according to the corresponding bit in this bit set. If a bit in the bit set is one, then the string has the character '1', otherwise the string's character is '0'. The string returned can be used as an argument to the message initWithString:position:count: to create a copy of this bit set.

See also:
- initWithString:position:count:
Returns:
a string describing this bit set

- (void) writeSelfToStream: (OLObjectOutStream *)  stream  

Write the object to a stream.

All instance variables are written to stream.

Parameters:
stream the stream to which to write.

Reimplemented from < OLStreamable >.


Member Data Documentation

- (unsigned) numberOfBits [protected]

The number of bits.

- (unsigned) numberOfWords [protected]

The number of words in the allocated range.

- (uint32_t*) words [protected]

The allocated memory for the bit set.


The documentation for this class was generated from the following file:
ObjectiveLibGenerated Sun Apr 22 15:12:57 2007, © 2004-2007 Will Mason
SourceForge.net Logo