forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitArray.h
More file actions
executable file
·171 lines (138 loc) · 4.69 KB
/
bitArray.h
File metadata and controls
executable file
·171 lines (138 loc) · 4.69 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Filename: bitArray.h
// Created by: drose (20Jan06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#ifndef BITARRAY_H
#define BITARRAY_H
#include "pandabase.h"
#include "bitMask.h"
#include "numeric_types.h"
#include "typedObject.h"
#include "indent.h"
#include "pointerToArray.h"
#include "checksumHashGenerator.h"
class SparseArray;
class BamWriter;
class BamReader;
class Datagram;
class DatagramIterator;
////////////////////////////////////////////////////////////////////
// Class : BitArray
// Description : A dynamic array with an unlimited number of bits.
//
// This is similar to a BitMask, except it appears to
// contain an infinite number of bits. You can use it
// very much as you would use a BitMask.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PUTIL BitArray {
public:
typedef BitMaskNative MaskType;
typedef MaskType::WordType WordType;
enum { num_bits_per_word = MaskType::num_bits };
PUBLISHED:
INLINE BitArray();
INLINE BitArray(WordType init_value);
INLINE BitArray(const BitArray ©);
INLINE BitArray &operator = (const BitArray ©);
BitArray(const SparseArray &from);
INLINE static BitArray all_on();
INLINE static BitArray all_off();
INLINE static BitArray lower_on(int on_bits);
INLINE static BitArray bit(int index);
INLINE static BitArray range(int low_bit, int size);
INLINE ~BitArray();
INLINE static bool has_max_num_bits();
INLINE static int get_max_num_bits();
INLINE static int get_num_bits_per_word();
INLINE int get_num_bits() const;
INLINE bool get_bit(int index) const;
INLINE void set_bit(int index);
INLINE void clear_bit(int index);
INLINE void set_bit_to(int index, bool value);
INLINE bool get_highest_bits() const;
bool is_zero() const;
bool is_all_on() const;
INLINE WordType extract(int low_bit, int size) const;
INLINE void store(WordType value, int low_bit, int size);
bool has_any_of(int low_bit, int size) const;
bool has_all_of(int low_bit, int size) const;
void set_range(int low_bit, int size);
void clear_range(int low_bit, int size);
INLINE void set_range_to(bool value, int low_bit, int size);
int get_num_on_bits() const;
int get_num_off_bits() const;
int get_lowest_on_bit() const;
int get_lowest_off_bit() const;
int get_highest_on_bit() const;
int get_highest_off_bit() const;
int get_next_higher_different_bit(int low_bit) const;
INLINE int get_num_words() const;
INLINE MaskType get_word(int n) const;
INLINE void set_word(int n, MaskType value);
void invert_in_place();
bool has_bits_in_common(const BitArray &other) const;
INLINE void clear();
void output(ostream &out) const;
void output_binary(ostream &out, int spaces_every = 4) const;
void output_hex(ostream &out, int spaces_every = 4) const;
void write(ostream &out, int indent_level = 0) const;
INLINE bool operator == (const BitArray &other) const;
INLINE bool operator != (const BitArray &other) const;
INLINE bool operator < (const BitArray &other) const;
int compare_to(const BitArray &other) const;
INLINE BitArray
operator & (const BitArray &other) const;
INLINE BitArray
operator | (const BitArray &other) const;
INLINE BitArray
operator ^ (const BitArray &other) const;
INLINE BitArray
operator ~ () const;
INLINE BitArray
operator << (int shift) const;
INLINE BitArray
operator >> (int shift) const;
void operator &= (const BitArray &other);
void operator |= (const BitArray &other);
void operator ^= (const BitArray &other);
void operator <<= (int shift);
void operator >>= (int shift);
public:
void generate_hash(ChecksumHashGenerator &hashgen) const;
private:
INLINE void copy_on_write();
void ensure_has_word(int n);
void normalize();
private:
typedef PTA(MaskType) Array;
Array _array;
int _highest_bits; // Either 0 or 1.
public:
void write_datagram(BamWriter *manager, Datagram &dg) const;
void read_datagram(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
register_type(_type_handle, "BitArray");
}
private:
static TypeHandle _type_handle;
};
#include "bitArray.I"
INLINE ostream &
operator << (ostream &out, const BitArray &array) {
array.output(out);
return out;
}
#endif