-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoublearray.h
76 lines (60 loc) · 1.93 KB
/
doublearray.h
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
#ifndef DOUBLEARRAY_H
#define DOUBLEARRAY_H
// {{SMILE_PUBLIC_HEADER}}
#include <cassert>
class DSL_intArray;
class DSL_doubleArray
{
public:
DSL_doubleArray()
{
items = 0;
size = numitems = 0;
}
DSL_doubleArray(int initialSize)
{
items = 0;
size = numitems = 0;
SetSize(initialSize);
}
DSL_doubleArray(const DSL_doubleArray &likeThisOne);
~DSL_doubleArray() { CleanUp(); }
int operator=(const DSL_doubleArray &likeThisOne);
void Swap(DSL_doubleArray &other);
double &operator[](int index) { assert(Ok(index)); return items[index]; }
const double &operator[](int index) const { assert(Ok(index)); return items[index]; }
double &Subscript(int index);
int GetSize() const { return size; }
int NumItems() const { return numitems; }
void UseAsList(int nItems = -1) {if (Ok(nItems)) numitems = nItems; else numitems = size;};
int Add(double thisNumber);
int Insert(int here, double thisNumber);
int Delete(int index);
int DeleteByContent(double thisContent);
int FindPosition(double ofThisNumber);
int IsInList(double aNumber);
void Flush(void) {numitems = 0;};
int RoomGuaranteed(int forThisPeople);
int SetSize(int thisSize);
double* Items() { return items; }
const double* Items() const { return items; }
int FillFrom(const DSL_doubleArray &thisOne);
void FillWith(double thisValue);
int ChangeOrder(const DSL_intArray &newPositions);
void CleanUp();
static void StartBlockCaching(int cacheSize);
static void StopBlockCaching();
private:
int Grow(void);
int Full(void) { return size == numitems; }
bool Ok(int index) const { return index >= 0 && index < size; }
bool DynamicMode() const { return items && (items != localItems); }
void SwapScalars(DSL_doubleArray &other);
void SwapWithDynamic(DSL_doubleArray &other);
enum { localSize = 4 };
double localItems[localSize];
double *items;
int size;
int numitems;
};
#endif