forked from llnl/zfp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray2d.h
More file actions
72 lines (60 loc) · 2.14 KB
/
array2d.h
File metadata and controls
72 lines (60 loc) · 2.14 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
#ifndef ARRAY2D_H
#define ARRAY2D_H
#include <climits>
#include <vector>
typedef unsigned int uint;
// uncompressed 2D double-precision array (for comparison)
namespace raw {
class array2d {
public:
// constructors
array2d() : nx(0), ny(0) {}
array2d(size_t nx, size_t ny, double = 0.0, const double* = 0, size_t = 0) : nx(nx), ny(ny), data(nx * ny, 0.0) {}
// array size
size_t size() const { return data.size(); }
size_t size_x() const { return nx; }
size_t size_y() const { return ny; }
void resize(size_t nx, size_t ny) { this->nx = nx; this->ny = ny; data.resize(nx * ny, 0.0); }
// rate in bits/value
double rate() const { return CHAR_BIT * sizeof(double); }
// cache size in bytes
size_t cache_size() const { return 0; }
// byte size of data structures
size_t size_bytes(uint mask = ZFP_DATA_ALL) const
{
size_t size = 0;
if (mask & ZFP_DATA_META)
size += sizeof(*this);
if (mask & ZFP_DATA_PAYLOAD)
size += data.size() * sizeof(double);
return size;
}
// accessors
double& operator()(size_t x, size_t y) { return data[x + nx * y]; }
const double& operator()(size_t x, size_t y) const { return data[x + nx * y]; }
double& operator[](size_t index) { return data[index]; }
const double& operator[](size_t index) const { return data[index]; }
// minimal-functionality forward iterator
class iterator {
public:
double& operator*() const { return array->operator[](index); }
iterator& operator++() { index++; return *this; }
iterator operator++(int) { iterator p = *this; index++; return p; }
bool operator==(const iterator& it) const { return array == it.array && index == it.index; }
bool operator!=(const iterator& it) const { return !operator==(it); }
size_t i() const { return index % array->nx; }
size_t j() const { return index / array->nx; }
protected:
friend class array2d;
iterator(array2d* array, size_t index) : array(array), index(index) {}
array2d* array;
size_t index;
};
iterator begin() { return iterator(this, 0); }
iterator end() { return iterator(this, nx * ny); }
protected:
size_t nx, ny;
std::vector<double> data;
};
}
#endif