00001
00002
00003
00004
00009 #ifndef __COLUMN_H__
00010 #define __COLUMN_H__
00011
00013
00014
00015 class c4_Column;
00016 class c4_ColIter;
00017 class c4_ColCache;
00018
00019 class c4_Persist;
00020 class c4_Strategy;
00021
00023
00024 class c4_Column
00025 {
00026 c4_PtrArray _segments;
00027 t4_i32 _position;
00028 t4_i32 _size;
00029 c4_Persist* _persist;
00030 t4_i32 _gap;
00031 int _slack;
00032 bool _dirty;
00033
00034 public:
00035 c4_Column (c4_Persist* persist_);
00036
00037 ~c4_Column ();
00038
00039 void SetBuffer(t4_i32);
00040
00041
00042 c4_Persist* Persist() const;
00043
00044 c4_Strategy& Strategy() const;
00045
00046 t4_i32 Position() const;
00047
00048 t4_i32 ColSize() const;
00049
00050 bool IsDirty() const;
00051
00052
00053 void SetLocation(t4_i32, t4_i32);
00054
00055 void PullLocation(const t4_byte*& ptr_);
00056
00057
00058 int AvailAt(t4_i32 offset_) const;
00059
00060 const t4_byte* LoadNow(t4_i32);
00061
00062 t4_byte* CopyNow(t4_i32);
00063
00064 void Grow(t4_i32, t4_i32);
00065
00066 void Shrink(t4_i32, t4_i32);
00067
00068 void SaveNow(c4_Strategy&, t4_i32 pos_);
00069
00070
00071 const t4_byte* FetchBytes(t4_i32 pos_, int len_, c4_Bytes& buffer_, bool forceCopy_);
00072
00073 void StoreBytes(t4_i32 pos_, const c4_Bytes& buffer_);
00074
00075
00076 bool RequiresMap() const;
00077 void ReleaseAllSegments();
00078
00079 static t4_i32 PullValue(const t4_byte*& ptr_);
00080 static void PushValue(t4_byte*& ptr_, t4_i32 v_);
00081
00082 void InsertData(t4_i32 index_, t4_i32 count_, bool clear_);
00083 void RemoveData(t4_i32 index_, t4_i32 count_);
00084 void RemoveGap();
00085
00086 enum { kSegBits = 12, kSegMax = 1 << kSegBits, kSegMask = kSegMax - 1 };
00087
00088 private:
00089 static int fSegIndex(t4_i32 offset_);
00090 static t4_i32 fSegOffset(int index_);
00091 static int fSegRest(t4_i32 offset_);
00092
00093 bool UsesMap(const t4_byte*) const;
00094 bool IsMapped() const;
00095
00096 void ReleaseSegment(int);
00097 void SetupSegments();
00098 void Validate() const;
00099 void FinishSlack();
00100
00101 void MoveGapUp(t4_i32 pos_);
00102 void MoveGapDown(t4_i32 pos_);
00103 void MoveGapTo(t4_i32 pos_);
00104
00105 t4_byte* CopyData(t4_i32, t4_i32, int);
00106 };
00107
00109
00110 class c4_ColOfInts : public c4_Column
00111 {
00112 public:
00113 c4_ColOfInts (c4_Persist* persist_, int width_ =sizeof (t4_i32));
00114
00115 int RowCount() const;
00116 void SetRowCount(int numRows_);
00117
00118 void FlipBytes();
00119
00120 int ItemSize(int index_);
00121 const void* Get(int index_, int& length_);
00122 void Set(int index_, const c4_Bytes& buf_);
00123
00124 t4_i32 GetInt(int index_);
00125 void SetInt(int index_, t4_i32 value_);
00126
00127 void Insert(int index_, const c4_Bytes& buf_, int count_);
00128 void Remove(int index_, int count_);
00129
00130 static int CalcAccessWidth(int numRows_, t4_i32 colSize_);
00131
00132 void SetAccessWidth(int bits_);
00133 void FixSize(bool fudge_);
00134 void ForceFlip();
00135
00136 static int DoCompare(const c4_Bytes& b1_, const c4_Bytes& b2_);
00137
00138 private:
00139 typedef void (c4_ColOfInts::*tGetter) (int);
00140 typedef bool (c4_ColOfInts::*tSetter) (int, const t4_byte*);
00141
00142 void Get_0b(int index_);
00143 void Get_1b(int index_);
00144 void Get_2b(int index_);
00145 void Get_4b(int index_);
00146 void Get_8i(int index_);
00147 void Get_16i(int index_);
00148 void Get_16r(int index_);
00149 void Get_32i(int index_);
00150 void Get_32r(int index_);
00151 void Get_64i(int index_);
00152 void Get_64r(int index_);
00153
00154 bool Set_0b(int index_, const t4_byte* item_);
00155 bool Set_1b(int index_, const t4_byte* item_);
00156 bool Set_2b(int index_, const t4_byte* item_);
00157 bool Set_4b(int index_, const t4_byte* item_);
00158 bool Set_8i(int index_, const t4_byte* item_);
00159 bool Set_16i(int index_, const t4_byte* item_);
00160 bool Set_16r(int index_, const t4_byte* item_);
00161 bool Set_32i(int index_, const t4_byte* item_);
00162 bool Set_32r(int index_, const t4_byte* item_);
00163 bool Set_64i(int index_, const t4_byte* item_);
00164 bool Set_64r(int index_, const t4_byte* item_);
00165
00166 void ResizeData(int index_, int count_, bool clear_ =false);
00167
00168 tGetter _getter;
00169 tSetter _setter;
00170
00171 union {
00172 t4_byte _item[8];
00173 double _aligner;
00174 };
00175
00176 int _currWidth;
00177 int _dataWidth;
00178 int _numRows;
00179 bool _mustFlip;
00180 };
00181
00183
00184 class c4_ColIter
00185 {
00186 c4_Column& _column;
00187 t4_i32 _limit;
00188 t4_i32 _pos;
00189 int _len;
00190 const t4_byte* _ptr;
00191
00192 public:
00193 c4_ColIter (c4_Column& col_, t4_i32 offset_, t4_i32 limit_);
00194
00195
00196 bool Next();
00197 bool Next(int max_);
00198
00199 const t4_byte* BufLoad() const;
00200 t4_byte* BufSave();
00201 int BufLen() const;
00202 };
00203
00205
00206 #if q4_INLINE
00207 #include "column.inl"
00208 #endif
00209
00211
00212 #endif