|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_DATA_FRAGTABLE_H
22 #define ELM_DATA_FRAGTABLE_H
24 #include <elm/assert.h>
30 template <
class T,
class E = Equiv<T>,
class A = DefaultAlloc>
37 : tab(8), size(1 << size_pow), msk(size - 1), shf(size_pow), used(size)
38 { ASSERTP(size_pow > 0,
"size must be greater than 0"); }
40 : tab(8), size(
t.size), msk(size - 1), shf(
t.shf), used(0)
46 inline bool pageFull()
const {
return used >= size; }
73 {
for(
int i = 0; i <
length(); i++)
if(
get(i) == v)
return true;
return false; }
75 {
for(
typename C::Iter i = c.items(); i; i++)
if(!
contains(*i))
return false;
return false; }
76 inline bool isEmpty()
const {
return tab.count() == 0; }
80 inline operator Iter(
void)
const {
return items(); }
82 {
Iter i =
begin(), j =
t.begin();
for(; i && j; i++, j++)
if(*i != *j)
return false;
return !i && !j; }
97 {
for(
int i = 0; i < tab.count(); i++)
delete [] tab[i]; tab.clear(); used = size; }
99 {
if(used >= size) { tab.add(
new T[size]); used = 0; }
100 tab[tab.length() - 1][used++] =
value; }
101 template <
template <
class _>
class C >
103 {
for(
typename C<T>::Iterator i(
items); i; i++)
add(i); }
105 {
for(
Iter i(*
this); i; i++)
if(i == item) {
remove(i);
break; } }
106 template <
template <
class _>
class C >
108 {
for(
typename C<T>::Iterator i(
items); i; i++)
remove(i); }
114 inline int length(
void)
const {
return ((tab.count() - 1) << shf) + used; }
115 inline const T&
get(
int index)
const
116 { ASSERTP(index >= 0 && index <
length(),
"index out of bounds");
return tab[index >> shf][index & msk]; }
118 {
for(
Iter i(*
this, start); i; i++)
119 if(i ==
value)
return i.i;
return -1; }
121 {
for(
int i = (start < 0 ?
length() : start) - 1; i >= 0; i--)
122 if(
get(i) ==
value)
return i;
return -1; }
127 { ASSERTP(length < this->
length(),
"length too big");
int nl = (
length + msk) >> shf;
128 for(
int i = nl; i < tab.count(); i++)
delete [] tab[i];
129 tab.setLength(nl); used =
length & msk;
if(!used) used = size; }
131 { ASSERTP(index >= 0 && index <
length(),
"index out of bounds"); tab[index >> shf][index & msk] =
value; }
134 { ASSERTP(index >= 0 && index <
length(),
"index out of bounds");
return tab[index >> shf][index & msk]; }
137 { ASSERTP(index >= 0 && index <=
length(),
"index out of bounds");
138 int len =
length();
alloc(1);
for(
int i = len - 1; i >= index; i--)
set(i + 1,
get(i));
set(index, item); }
142 int len =
length();
for(
int i = index + 1; i < len; i++)
set(i - 1,
get(i));
143 used--;
if(!used) {
delete [] tab[tab.count() - 1]; tab.setLength(tab.count() - 1); used = size; }
149 {
int res =
length();
while(
count >= size - used) {
count -= size - used; tab.add(
new T[size]); used = 0; }
150 used +=
count;
return res; }
154 int size, msk, shf, used;
157 template <
class T,
class E,
class A>
162 #endif // ELM_DATA_FRAGTABLE_H
Iter begin() const
Definition: FragTable.h:68
Iter items(void) const
Definition: FragTable.h:78
bool ended(void) const
Definition: FragTable.h:54
void next(void)
Definition: FragTable.h:52
Definition: util_WAHVector.cpp:157
Iter operator*(void) const
Definition: FragTable.h:79
int length(void) const
Definition: FragTable.h:114
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
MutIter(self_t &c, int p=0)
Definition: FragTable.h:90
bool operator<=(const T &v, const FragTable< T, E, A > &t)
Definition: FragTable.h:158
void set(const Iter &iter, const T &item)
Definition: FragTable.h:132
Definition: FragTable.h:48
void insert(const Iter &iter, const T &item)
Definition: FragTable.h:139
bool containsAll(const C &c) const
Definition: FragTable.h:74
FragTable< T, E, A > self_t
Definition: FragTable.h:34
T & operator[](int index)
Definition: FragTable.h:135
int alloc(int count)
Definition: FragTable.h:148
FragTable(int size_pow=8)
Definition: FragTable.h:36
T & get(int index)
Definition: FragTable.h:133
bool operator==(const self_t &t) const
Definition: FragTable.h:83
int pagePower() const
Definition: FragTable.h:45
FragTable(const FragTable &t)
Definition: FragTable.h:39
self_t & operator-=(const T &v)
Definition: FragTable.h:111
self_t & operator+=(const T &v)
Definition: FragTable.h:110
MutIter end()
Definition: FragTable.h:94
void removeAll(const C< T > &items)
Definition: FragTable.h:107
T & item()
Definition: FragTable.h:91
bool contains(const T &v) const
Definition: FragTable.h:72
void removeAt(int index)
Definition: FragTable.h:141
int len
Definition: FragTable.h:59
T t
Definition: FragTable.h:33
bool isEmpty() const
Definition: FragTable.h:76
void addAll(const C< T > &items)
Definition: FragTable.h:102
const T & item() const
Definition: FragTable.h:53
void remove(const T &item)
Definition: FragTable.h:104
bool equals(const BaseIter &it) const
Definition: FragTable.h:55
int indexOf(const T &value, int start=0) const
Definition: FragTable.h:117
BaseIter()
Definition: FragTable.h:50
void removeAt(const Iter &iter)
Definition: FragTable.h:145
bool equals(const self_t &t) const
Definition: FragTable.h:81
MutIter()
Definition: FragTable.h:89
void set(int index, const T &value)
Definition: FragTable.h:130
int lastIndexOf(const T &value, int start=-1) const
Definition: FragTable.h:120
const T & operator[](int index) const
Definition: FragTable.h:123
~FragTable(void)
Definition: FragTable.h:42
int i
Definition: FragTable.h:59
int pageSize() const
Definition: FragTable.h:44
const T & item() const
Definition: FragTable.h:66
BaseIter(const self_t &array, int pos=0)
Definition: FragTable.h:51
void shrink(int length)
Definition: FragTable.h:126
bool operator!=(const self_t &t) const
Definition: FragTable.h:84
Definition: FragTable.h:87
T * alloc() const
Definition: custom.h:33
Definition: FragTable.h:63
int count(void) const
Definition: FragTable.h:71
void clear(void)
Definition: FragTable.h:96
void insert(int index, const T &item)
Definition: FragTable.h:136
Iter end() const
Definition: FragTable.h:69
bool pageFull() const
Definition: FragTable.h:46
Definition: FragTable.h:31
void remove(const Iter &iter)
Definition: FragTable.h:109
const self_t * arr
Definition: FragTable.h:58
MutIter begin()
Definition: FragTable.h:93
void add(const T &value)
Definition: FragTable.h:98
const T & get(int index) const
Definition: FragTable.h:115