Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
92c5c0f
Added the design of HTM-SubTree libraries
TonHai1111 May 19, 2021
7923a7b
Added constructors to load Sub-Tree from file and helper functions
TonHai1111 May 26, 2021
4b2bfab
Fixed createChildNode function and some helper functions
TonHai1111 May 26, 2021
b9856b6
Implemented intersect function
TonHai1111 Jun 8, 2021
6830793
Fixed bugs in intersect, printSubTree functions
TonHai1111 Jun 15, 2021
e1a505f
Fixed duplication stare encode insertion. Added full stare encode for…
TonHai1111 Jun 16, 2021
62da0aa
Added test cases for data loading and intersect
TonHai1111 Jul 14, 2021
817c6da
Fixed group leaves. Fixed print real key at leaf-nodes. Added print2F…
TonHai1111 Jul 19, 2021
cb09fda
Fixed level information of the keys in the leaves.
TonHai1111 Jul 22, 2021
c325ee4
Fixed group leaf bug.
TonHai1111 Jul 23, 2021
dd0dfe1
Fixed group leaves bug.
TonHai1111 Jul 23, 2021
e9394e8
Added check overlapping check between two SubTree and containing check
TonHai1111 Aug 5, 2021
9a1ccb0
Added leftJoin, innerJoin, fullJoin and their helper functions
TonHai1111 Aug 6, 2021
ed3d81c
Replace HstmRange by HTMSubTree in SpatialRange.h and SpatialRange.cpp.
TonHai1111 Aug 9, 2021
ca66023
Added interface for leftjoin, innerjoin and fulljoin to SpatialRange
TonHai1111 Aug 9, 2021
cfb1bbe
Fixed parameters bug.
TonHai1111 Aug 11, 2021
515ab28
Added back the range in SpatialRange for temporary compile and testing
TonHai1111 Aug 11, 2021
6f0e7eb
Updated .gitignore
TonHai1111 Aug 24, 2021
1ecc788
Remote rebase and local commits
TonHai1111 Aug 26, 2021
375bfb6
Fixed merge conflicts
TonHai1111 Aug 26, 2021
a038c91
Fixed interface bugs
TonHai1111 Aug 26, 2021
79fca93
Fixed isIntersect parameter bug
TonHai1111 Aug 27, 2021
533c4e0
Fixed contains addSpatialInterval bugs
TonHai1111 Aug 28, 2021
3fbe839
Fixed error with isContain. Added tests for isContain
TonHai1111 Aug 29, 2021
d294289
Fixed getAllLeaves, HTMSubTree<list> contructor, addSpatialRange. Add…
TonHai1111 Aug 29, 2021
923d769
Fixed type error. Removed range in spatialRange
TonHai1111 Aug 31, 2021
58813e4
Added join tests
TonHai1111 Sep 13, 2021
66b05ee
Fixed leftJoin bugs. Added innerJoin and fullJoin tests
TonHai1111 Sep 14, 2021
a4799a3
Fixed fullJoin bugs
TonHai1111 Sep 14, 2021
96bb883
Removed a debug message
TonHai1111 Sep 15, 2021
3dcd5eb
Added isIntersect and its helper functions. Cleaned up source code
TonHai1111 Sep 17, 2021
84acd7e
Fixed the list of returned sids for intersect function.
TonHai1111 Sep 21, 2021
9b50e5b
Added a flag to disable tryGroupLeaves.
TonHai1111 Sep 21, 2021
50fdc33
Added back the testcases
TonHai1111 Oct 6, 2021
a0b5d82
Merge branch 'htm-subtree' of github.com:SpatioTemporal/STARE into ht…
TonHai1111 Oct 6, 2021
15954ec
Added testcases
TonHai1111 Oct 6, 2021
7ee061a
added subtree headers to install
NiklasPhabian Oct 6, 2021
a2d6340
avoid version conflict. We certainly have to bump version with the Su…
NiklasPhabian Oct 6, 2021
ecae7e4
Merge branch 'master' into htm-subtree
NiklasPhabian Oct 6, 2021
512ea67
1.2.5
NiklasPhabian Oct 6, 2021
f60877b
Merge branch 'htm-subtree' of github.com:SpatioTemporal/STARE into ht…
NiklasPhabian Oct 6, 2021
253ff3d
downgrade cmake
NiklasPhabian Oct 7, 2021
3ef4307
Fixed return empty list instead of NULL for the intersect and join fu…
TonHai1111 Oct 19, 2021
113ae17
Merge branch 'htm-subtree' of github.com:SpatioTemporal/STARE into ht…
TonHai1111 Oct 19, 2021
64fb5bb
Merge branch 'master' into htm-subtree
NiklasPhabian Jun 2, 2023
58ba13b
install instructions
NiklasPhabian Jun 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cmake_minimum_required(VERSION 3.18)
cmake_minimum_required(VERSION 3.16)

project(STARE VERSION 1.2.8
DESCRIPTION "SpatioTemporal Adaptive Resolution Encoding for combining diverse geodata."
Expand Down
1 change: 1 addition & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ ctest -T memcheck
sudo apt install cmake # Might need to manually update to 3.15+
# sudo apt install liberfa-dev # optional, STARE contains a copy
sudo apt install g++
sudo apt install doxygen

###########################################################################
#
Expand Down
4 changes: 4 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ set (
${CMAKE_CURRENT_SOURCE_DIR}/HtmRangeMultiLevelIterator.h
${CMAKE_CURRENT_SOURCE_DIR}/Htmio.h
${CMAKE_CURRENT_SOURCE_DIR}/HstmRange.h
${CMAKE_CURRENT_SOURCE_DIR}/HTMSubTreeNode.h
${CMAKE_CURRENT_SOURCE_DIR}/HTMSubTree.h
${CMAKE_CURRENT_SOURCE_DIR}/NameEncoding.h
${CMAKE_CURRENT_SOURCE_DIR}/PySTARE.h
${CMAKE_CURRENT_SOURCE_DIR}/RangeConvex.h
Expand Down Expand Up @@ -69,6 +71,8 @@ install(FILES STARE.h
HtmRangeMultiLevelIterator.h
Htmio.h
HstmRange.h
HTMSubTreeNode.h
HTMSubTree.h
KeyPair.h
NameEncoding.h
RangeConvex.h
Expand Down
140 changes: 140 additions & 0 deletions include/HTMSubTree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

#ifndef INCLUDE_HTMSUBTREE_H
#define INCLUDE_HTMSUBTREE_H

#include "HTMSubTreeNode.h"
#include <list>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "STARE.h"

#include <cassert>
#include <chrono>
#include <cstdlib>

//These types are already defined in STARE.h
//typedef unsigned long long STARE_ArrayIndexSpatialValue;
//typedef std::vector<STARE_ArrayIndexSpatialValue> STARE_SpatialIntervals;

class HTMSubTree{
public:
// Contructors
HTMSubTree();
HTMSubTree(char* sidecar);//Load HTMSubTree from sidecar file
HTMSubTree(STARE_SpatialIntervals sids);//Load HTMSubTree from list of STARE values
HTMSubTree(STARE_SpatialIntervals sids, bool _isGroupLeaves);//Load HTMSubTree from list of STARE values
HTMSubTree(std::list<STARE_ENCODE> *sids);
HTMSubTree(std::list<STARE_ENCODE> *sids, bool _isGroupLeaves);

// Destructors
~HTMSubTree();

// Attributes
HTMSubTreeNode* root;
bool multipleResolution = true; //true (default value): allow multiple resolution in the tree
//false: allow only one resolution in the tree
bool isGroupLeaves = true;// true: allow tryGroupLeaves to run
//false: don't allow tryGroupLeaves to run

// Methods
bool isIntersect(HTMSubTreeNode* Ins_root); // return if there is any overlapping
bool isContain(STARE_ArrayIndexSpatialValue siv); //return if siv is contained in HTMSubTree
bool isIntersect(STARE_ArrayIndexSpatialValue siv);

std::list<list<STARE_ENCODE>>* leftJoin(HTMSubTreeNode* Ins_root);
std::list<list<STARE_ENCODE>>* innerJoin(HTMSubTreeNode* Ins_root);
std::list<list<STARE_ENCODE>>* fullJoin(HTMSubTreeNode* Ins_root);

std::list<STARE_ENCODE>* intersect(HTMSubTreeNode* Ins_root); // Return a list of STARE_ENCODE

void printTree();

void printFromNode(HTMSubTreeNode* current);

void printTree2File(char* filename);
void printFromNode2File(HTMSubTreeNode* current, ofstream& outputstream);

//protected:
void addSTAREID(STARE_ENCODE key);
int getAllLeaves(HTMSubTreeNode * sub_root, std::list<list<STARE_ENCODE>>* result);
int getAllLeaves(HTMSubTreeNode * sub_root, std::list<STARE_ENCODE>* result);

//private:
HTMSubTreeNode* createChildNode(HTMSubTreeNode* current, STARE_ArrayIndexSpatialValue code, STARE_ENCODE level);
// Helper functions
STARE_ENCODE getSTARELEVELCode(STARE_ENCODE key, STARE_ENCODE level);
HTMSubTreeNode* getHighestRoot(HTMSubTreeNode* Ins_root);
HTMSubTreeNode* getPotentialBranch(HTMSubTreeNode* root_a, HTMSubTreeNode* root_b);
void tryGroupLeaves(HTMSubTreeNode* curNode, std::list<HTMSubTreeNode*> *path);
bool check_Contain(STARE_ENCODE key_a, STARE_ENCODE key_b);
bool check_Intersect(STARE_ENCODE key_a, STARE_ENCODE key_b);

int rec_intersect(HTMSubTreeNode* root_a, HTMSubTreeNode* root_b, std::list<STARE_ENCODE> * result);
bool rec_isContain(HTMSubTreeNode* sub_root, STARE_ArrayIndexSpatialValue siv);
bool rec_isIntersect(HTMSubTreeNode* sub_root, STARE_ArrayIndexSpatialValue siv);
bool rec_isIntersect(HTMSubTreeNode* root_a, HTMSubTreeNode* root_b);
int rec_LeftJoin(HTMSubTreeNode *root_a, HTMSubTreeNode* root_b, std::list<list<STARE_ENCODE>>* result);
int rec_InnerJoin(HTMSubTreeNode *root_a, HTMSubTreeNode* root_b, std::list<list<STARE_ENCODE>>* result);
int rec_FullJoin(HTMSubTreeNode *root_a, HTMSubTreeNode* root_b, std::list<list<STARE_ENCODE>>* result);

};

void HTMSubTree_test_Create_Print();
void HTMSubTree_test_HighestRoot();
void HTMSubTree_test_GetPotentialBranch();
void HTMSubTree_test_Intersect();
void HTMSubTree_test_Create_Duplicate_Print();
void HTMSubTree_vs_SpatialRange_Create_small();
void HTMSubTree_vs_SpatialRange_Create_large();
void HTMSubTree_vs_SpatialRange_Create_MOD05_1();
void HTMSubTree_vs_SpatialRange_Create_MOD05_2();
void HTMSubTree_vs_SpatialRange_Create_VNP03DNB_1();
void HTMSubTree_vs_SpatialRange_Intersect_small();
void HTMSubTree_vs_SpatialRange_Intersect_large();
void HTMSubTree_vs_SpatialRange_Intersect_MOD05_1();
void HTMSubTree_vs_SpatialRange_Intersect_MOD05_2();
void HTMSubTree_vs_SpatialRange_Intersect_VNP03DNB_1();
void HTMSubTree_vs_SpatialRange_Intersect_MOD05_2_verify();
void HTMSubTree_test_isContain();
void HTMSubTree_test_getAllLeaves();
void HTMSubTree_test_isIntersect();
void HTMSubTree_test_leftJoin();
void HTMSubTree_test_innerJoin();
void HTMSubTree_test_fullJoin();
/* ========== <Timer class> =========== */
class timer
{

std::chrono::system_clock::time_point startCounter;
std::chrono::system_clock::time_point endCounter;
double result = 0.0;
double resultInSecond = 0.0;
double resultInMilliSecond = 0.0;
double resultInMicroSecond = 0.0;

public:
timer();

void start();

void end();

void reStart();


void reStartValue(double value);


double getResult();

double getResultInSecond();

double getResultInMilliSecond();

double getResultInMicroSecond();
};


#endif /* INCLUDE_HTMSUBTREE_H_ */
60 changes: 60 additions & 0 deletions include/HTMSubTreeNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

#ifndef INCLUDE_HTMSUBTREENODE_H
#define INCLUDE_HTMSUBTREENODE_H
#include <stdint.h>
#include <cstddef>
#include <list>
#include <iostream>
#include <string>
#include <vector>

#include "General.h"
#include "SpatialGeneral.h"

//TODO: These types should be combined with STARE.h
// (i.e., Key == STARE_ENCODE == STARE_ArrayIndexSpatialValue)
// int64 and uint64 are defined in SpatialGeneral.h
//typedef unsigned long long Key; // STARE Encode - 64 bits
//typedef unsigned long long STARE_ENCODE;
typedef uint64 STARE_ENCODE;

int const MAX_NUM_CHILD = 8; // 8 children in the first level, and 4 children in other levels.
int const MAX_NUM_CHILD_II = 4;

/*class HTMSubTreeNodeEntry{
public:
HTMSubTreeNodeEntry();
HTMSubTreeNodeEntry(Key _key);
~HTMSubTreeNodeEntry();
HTMSubTreeNode* child;
Key key; // Key is stored twice (in the current node and in its entries),
// since its will be easier in
// travesing the subtree (one step is reduced).
};*/

class HTMSubTreeNode{
public:
// Contructors
HTMSubTreeNode();
HTMSubTreeNode(STARE_ENCODE _key, bool _isLeaf, STARE_ENCODE _level, int _count);

// Destructors
~HTMSubTreeNode();

// Attributes
STARE_ENCODE key; // STARE Encode
STARE_ENCODE level; // 0 <= level <= 27, (0 is the highest level)
// Tree Hierachical level (node coverage)
bool isLeaf; // True or False
int count; // Total number of children
//int dataResolution; // 0 <= level <= 27, (leaf level)
// // Resolution level

//entries
HTMSubTreeNode* children[MAX_NUM_CHILD];
STARE_ENCODE keys[MAX_NUM_CHILD];

private:
STARE_ENCODE genSTARELEVELCode(STARE_ENCODE key, STARE_ENCODE level, unsigned int pos);
};
#endif /* INCLUDE_HTMSUBTREENODE_H_ */
62 changes: 28 additions & 34 deletions include/SpatialRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,54 @@

#include "STARE.h"
#include "HstmRange.h"
#include "HTMSubTree.h"

/**
* A wrapper for an HstmRange that knows about STARE to provide htm-range-like functions.
*
*/
class SpatialRange {
public:
SpatialRange();
SpatialRange(STARE_SpatialIntervals intervals);
SpatialRange(HstmRange *range) { this->range = range; }
virtual ~SpatialRange();
SpatialRange();
SpatialRange(STARE_SpatialIntervals intervals);
SpatialRange(STARE_SpatialIntervals intervals, bool isGroupLeaves);
SpatialRange(HTMSubTree *tree){ this->tree = tree;}
SpatialRange(std::list<STARE_ENCODE> *sids);
SpatialRange(std::list<STARE_ENCODE> *sids, bool isGroupLeaves);
virtual ~SpatialRange();

void addSpatialIntervals(STARE_SpatialIntervals intervals);
void addSpatialIntervals(STARE_SpatialIntervals intervals, bool _isGroupLeaves);
void addSpatialRange(const SpatialRange& r);

STARE_SpatialIntervals toSpatialIntervals();
int getNextSpatialInterval(STARE_SpatialIntervals &interval);
int getNextSpatialInterval(STARE_SpatialIntervals &interval);//Don't need this

bool contains(STARE_ArrayIndexSpatialValue siv) {
// cout << "sr::c " << flush;
EmbeddedLevelNameEncoding leftJustified;
leftJustified.setIdFromSciDBLeftJustifiedFormat(siv);
return range->range->isIn(leftJustified.maskOffLevelBit());
return tree->isContain(siv);
}

void print(){
tree->printTree();
}

bool intersects(STARE_ArrayIndexSpatialValue siv) {
EmbeddedLevelNameEncoding leftJustified;
leftJustified.setIdFromSciDBLeftJustifiedFormat(siv);
Key lo = leftJustified.maskOffLevelBit();
Key hi = lo;
#if 0
KeyPair pr = KeyPair(lo,hi);
#endif
int rstat = range->range->contains(lo,hi);
bool intersectp = rstat != 0; // 0:no-intersection;-1:partial;1:full.
return intersectp;
return tree->isIntersect(siv);
}

HstmRange *range;
HTMSubTree *tree;

/////////// private: Maybe? ////////////
std::list<list<STARE_ENCODE>>* leftJoin(SpatialRange* sp);
std::list<list<STARE_ENCODE>>* innerJoin(SpatialRange* sp);
std::list<list<STARE_ENCODE>>* fullJoin(SpatialRange* sp);

// Maybe inherit these?
// TODO Note the int in the following is a return code, not an index.
int getNext(KeyPair &kp) {
int istat = range->getNext(kp);
// cout << "<istat=" << istat << ">" << flush;
return istat;
};
void reset() { range->reset(); } // range not null?
void purge() { range->purge(); } // what if range null?
void defrag() { range->range->defrag(); } // Defragment intervals without changing resolution
void compress() { range->range->CompressionPass(); } // Defragment and coarsen resolution where possible
//Mike suggested to remove these functions
int getNext(KeyPair &kp) {}
void reset() {}
void purge() { print(); }
void defrag() {}
void compress() {}
//////////////////////////////////////////////

#define FMTX(x) " 0x" << setw(16) << hex << x << dec
void dump() {
Expand Down Expand Up @@ -118,11 +113,10 @@ class SpatialRange {
}
};

SpatialRange* sr_intersect(const SpatialRange& a, const SpatialRange& b, bool compress = false);
SpatialRange* sr_intersect(const SpatialRange& a, const SpatialRange& b, bool compress = false, bool isGroupLeaves=true);

inline SpatialRange* operator& ( const SpatialRange& a, const SpatialRange& b) {
return sr_intersect(a,b);
// return new SpatialRange(new HstmRange(a.range->range->RangeFromIntersection(b.range->range))); // NOTE mlr Probably about the safest way to inst. SpatialRange.
}
void SpatialRange_test();

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ set (
HtmRangeMultiLevelIterator.cpp
Htmio.cpp
HstmRange.cpp
HTMSubTreeNode.cpp
HTMSubTree.cpp
NameEncoding.cpp
RangeConvex.cpp
SkipList.cpp
Expand Down
Loading