HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_DataBitArray.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_DataBitArray.h ( GA Library, C++)
7  *
8  * COMMENTS: A very simple array used to store attribute data. Some areas
9  * of the array may be "vacant".
10  */
11 
12 #ifndef __GA_DataBitArray__
13 #define __GA_DataBitArray__
14 
15 #include "GA_API.h"
16 #include "GA_Types.h"
17 
18 #include <UT/UT_Array.h>
19 
20 #include <SYS/SYS_Types.h>
21 
22 #include <iosfwd>
23 #include <stddef.h>
24 
25 
26 class GA_Defragment;
27 class GA_LoadMap;
28 class GA_MergeMap;
29 class GA_MergeOffsetMap;
30 class GA_Range;
31 class UT_IStream;
32 class UT_JSONWriter;
33 class UT_JSONParser;
34 class UT_JSONValue;
35 class UT_MemoryCounter;
36 class UT_Options;
37 
38 class ga_DataBitArrayPage;
39 
40 // We want a bit pattern the size of a pointer whose every bit
41 // but the last is set.
42 #define GA_BIT_PAGE_PTR_MASK ( ~((size_t)1) )
43 
44 /// @brief An array of bits.
45 ///
46 /// GA_DataBitArray provides an efficient way of storing bit arrays.
47 ///
48 /// There are basic operations on the array.
49 ///
50 /// See also: @ref JSON-GA_DataBitArray
51 ///
53 {
54 public:
56  ~GA_DataBitArray();
57 
58  /// Change the size of the array
59  void setArraySize(GA_Offset size);
60 
61  /// Query the size of the array
62  GA_Offset getArraySize() const { return mySize; }
63 
64  /// Clear all entries to the default value
65  void clear();
66 
67  /// Clear a specific offset to the default
68  void clearOffset(GA_Offset off, GA_Offset num);
69 
70  /// Set all entries to the given value
71  void makeConstant(bool value);
72 
73  /// Try to compress all pages overlapping the specified offset range.
74  void tryCompressAllPages(GA_Offset start_offset = GA_Offset(0),
75  GA_Offset end_offset = GA_INVALID_OFFSET);
76 
77  /// Harden all pages overlapping the specified offset range.
78  void hardenAllPages(GA_Offset start_offset = GA_Offset(0),
79  GA_Offset end_offset = GA_INVALID_OFFSET);
80 
81  /// Report memory usage
82  int64 getMemoryUsage(bool inclusive) const;
83 
84  /// Count memory usage using a UT_MemoryCounter in order to count
85  /// shared memory correctly.
86  /// If inclusive is true, the size of this object is counted,
87  /// else only memory owned by this object is counted.
88  /// If this is pointed to by the calling object, inclusive should be true.
89  /// If this is contained in the calling object, inclusive should be false.
90  /// (Its memory was already counted in the size of the calling object.)
91  void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
92 
93  /// Copy bit array from the source. This will change the size
94  /// of the array if the source size is different.
95  bool copyFrom(const GA_DataBitArray &src);
96 
97  /// mergeGrowArrayAndCopy() is called to grow the data array while
98  /// appending or copying data from the source (non-interleaved merge).
99  /// The array is resized to the new destination capacity (as defined by
100  /// the map) and the data from the source array is copied over into the
101  /// newly allocated area.
102  void mergeGrowArrayAndCopy(const GA_MergeMap &map,
103  GA_AttributeOwner owner,
104  const GA_DataBitArray &src);
105 
106  GA_Size countSetBits(GA_Offset start, GA_Offset end) const;
107  /// Query the length of repeated bit values starting from 'start' until
108  /// 'end' or a change in bit values.
109  void getConstantSpan(GA_Offset start, GA_Offset end, GA_Size &size, bool &value) const;
110 
111  /// Access data from the array
112  bool get(GA_Offset idx) const;
113  /// Test if any bit in the range is set
114  bool isAnySet(const GA_Range &range) const;
115 
116  /// Set the value at a particular index
117  void set(GA_Offset di, bool val);
119  { set(di, src.get(si)); }
120  void set(const GA_Range &it, bool val);
121  void set(const GA_Range &it, const GA_DataBitArray &src);
122  void set(const GA_Range &it, const GA_DataBitArray &src, const GA_Range &sit);
123  void set(const GA_DataBitArray &src, const GA_Range &sit,
124  const GA_MergeOffsetMap &map);
125 
126  /// @{
127  /// Interface for defragmentation
128  void defragment(const GA_Defragment &defrag);
129  /// @}
130 
131  /// Toggle the value at a particular index
132  bool toggle(GA_Offset idx);
133  void toggle(const GA_Range &it);
134 
135  /// Page accelerated full group operations
136  void andEqual(const GA_DataBitArray &src);
137  void xorEqual(const GA_DataBitArray &src);
138  void orEqual(const GA_DataBitArray &src);
139  void subEqual(const GA_DataBitArray &src);
140  void toggleAll(GA_Size numelements);
141 
142  /// A special method for loading group data from geo files.
143  bool loadGroupBitArrayH9(UT_IStream &is);
144  bool saveGroupBitArrayH9(std::ostream &os, int binary,
145  const GA_Range &it) const;
146 
147  /// @section JSON-GA_DataBitArray JSON Schema: GA_DataBitArray
148  /// jsonSave() will save the array to a JSON stream. There are multiple
149  /// ways to store a bit-array.
150  /// @code
151  /// {
152  /// "name" : "GA_DataBitArray",
153  /// "description" : "A array bits",
154  /// "type" : "orderedmap",
155  /// "properties" : [
156  /// "boolRLE": {
157  /// "type" : "array",
158  /// "items" : [ "integer", "boolean" ]
159  /// "optional" : true,
160  /// "description": "A run length encoded bit array stored as a
161  /// count/bool pair where the 'bool' value is
162  /// repeated 'count' times.",
163  /// }
164  /// "i8": {
165  /// "type" : "array",
166  /// "items" : "integer",
167  /// "description" : "A array of 0/1, not very efficient",
168  /// "optional" : true,
169  /// }
170  /// ]
171  /// }
172  /// @endcode
173  /// @see @ref JSON_FileFormat
174  bool jsonSave(UT_JSONWriter &w, const GA_Range &it,
175  const UT_Options *options) const;
176 
177  /// Load from a JSON stream
178  bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &map,
179  GA_AttributeOwner owner);
180  /// Load from a JSON value
181  bool jsonLoad(UT_JSONParser &p, const UT_JSONValue &v,
182  const GA_LoadMap &map, GA_AttributeOwner owner);
183 
184 private:
185  inline bool isPageConstant(GA_PageNum pageid) const
186  { return !(((size_t)myPages(pageid)) & GA_BIT_PAGE_PTR_MASK); }
187  void tryCompressPage(GA_PageNum pageid);
188  void makePageConstant(GA_PageNum pageid, bool value);
189  inline bool getPageCVal(GA_PageNum pageid) const
190  { return (bool) (myPages(pageid)); }
191 
192  void reallocPageTable(GA_Offset size);
193  ga_DataBitArrayPage *harden(GA_PageNum pageid);
194 
195  bool myDefault;
197  GA_Offset mySize;
198 };
199 
200 #endif
GA_Offset getArraySize() const
Query the size of the array.
GLenum GLint * range
Definition: glcorearb.h:1924
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GLsizeiptr size
Definition: glcorearb.h:663
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:100
bool get(GA_Offset idx) const
Access data from the array.
GLuint GLuint end
Definition: glcorearb.h:474
Keeps track of offset mapping when merging index lists.
void set(GA_Offset di, const GA_DataBitArray &src, GA_Offset si)
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
#define GA_BIT_PAGE_PTR_MASK
GLsizei const GLfloat * value
Definition: glcorearb.h:823
GA_AttributeOwner
Definition: GA_Types.h:33
A map of string to various well defined value types.
Definition: UT_Options.h:42
GA_Size GA_PageNum
Definition: GA_Types.h:620
GLuint GLfloat * val
Definition: glcorearb.h:1607
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:75
png_infop png_uint_32 int num
Definition: png.h:2158
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
An array of bits.
GLenum src
Definition: glcorearb.h:1792