EPICS ARCHIVER V4
|
Implements a file-based RTree. More...
#include <RTree.h>
Classes | |
class | Datablock |
Each RTree leaf points to Datablocks; they describe where the actual data that the index references resides via a filename and an offset into that file. More... | |
Public Member Functions | |||
RTree (FileAllocator &fa, FileOffset anchor) | |||
Attach RTree to FileAllocator. More... | |||
void | init (int M) | ||
Initialize empty tree. More... | |||
void | reattach () | ||
Re-attach to an existing tree. More... | |||
int | getM () const | ||
The 'M' value, i.e. More... | |||
Interval | getInterval () | ||
Return range covered by this RTree
| |||
Datablock * | search (const epicsTime &start) const | ||
Locate data after start time. More... | |||
Datablock * | getFirstDatablock () const | ||
Datablock * | getLastDatablock () const | ||
class Node | chooseLeaf (const Interval &range) | ||
bool | insertDatablock (const Interval &range, FileOffset data_offset, const stdString &data_filename) | ||
Create and insert a new Datablock. More... | |||
size_t | removeDatablock (const Interval &range, FileOffset data_offset, const stdString &data_filename) | ||
Remove reference to given data block. More... | |||
bool | updateLastDatablock (const Interval &range, FileOffset data_offset, stdString data_filename) | ||
Tries to update existing datablock. More... | |||
void | makeDot (const char *filename) | ||
Create a graphviz 'dot' file. More... | |||
bool | selfTest (unsigned long &nodes, unsigned long &records) | ||
Returns true if tree passes self test, otherwise prints errors. More... | |||
Static Public Attributes | |
static const size_t | anchor_size = 8 |
Implements a file-based RTree.
See the Antonin Guttman paper "R-Trees: A Dynamic Index Structure for Spatial Searching" (Proc. 1984 ACM-SIGMOD Conference on Management of Data, pp. 47-57).
The records are time intervals start...end. In addition to what's described in the Guttman paper,
RTree::RTree | ( | FileAllocator & | fa, |
FileOffset | anchor | ||
) |
Attach RTree to FileAllocator.
fa,: | The file allocator |
anchor,: | The RTree will deposit its root pointer there. Caller needs to assert that there are RTree::anchor_size bytes available at that location in the file. |
class Node RTree::chooseLeaf | ( | const Interval & | range | ) |
Datablock* RTree::getFirstDatablock | ( | ) | const |
GenericException | on read error. |
Datablock* RTree::getLastDatablock | ( | ) | const |
|
inline |
The 'M' value, i.e.
Node size, of this RTree.
void RTree::init | ( | int | M | ) |
bool RTree::insertDatablock | ( | const Interval & | range, |
FileOffset | data_offset, | ||
const stdString & | data_filename | ||
) |
Create and insert a new Datablock.
Note: Once a data block (offset and filename) is inserted for a given start and end time, the RTree code assumes that it stays that way. I.e. if we try to insert the same start/end/offset/file again, this will result in a NOP and return false. It is an error to insert the same offset/file again with a different start and/or end time!
GenericException | on write error. |
void RTree::makeDot | ( | const char * | filename | ) |
Create a graphviz 'dot' file.
void RTree::reattach | ( | ) |
size_t RTree::removeDatablock | ( | const Interval & | range, |
FileOffset | data_offset, | ||
const stdString & | data_filename | ||
) |
Remove reference to given data block.
GenericException | on internal error. |
Datablock* RTree::search | ( | const epicsTime & | start | ) | const |
Locate data after start time.
Specifically, the last record with data at or just before the start time is returned, so that the user can then decide if and how that value might extrapolate onto the start time. There's one exception: When requesting a start time that preceeds the first available data point, so that there is no previous data point, the very first record is returned.
GenericException | on read error. |
bool RTree::selfTest | ( | unsigned long & | nodes, |
unsigned long & | records | ||
) |
Returns true if tree passes self test, otherwise prints errors.
On success, nodes will contain the number of nodes in the tree and record contains the number of used records. One can compare that to the total number of available records, nodes*getM().
bool RTree::updateLastDatablock | ( | const Interval & | range, |
FileOffset | data_offset, | ||
stdString | data_filename | ||
) |
Tries to update existing datablock.
Tries to update the end time of the last datablock, in case start, data_offset and data_filename all match. Will otherwise fall back to insertDatablock.
GenericException | on write error. |
|
static |