Tuesday, 15 June 2010

c++ - what should be the format of input data file which is passed as an object to MyDataStream stream(argv[1]) -



c++ - what should be the format of input data file which is passed as an object to MyDataStream stream(argv[1]) -

i using "libspatialindex" library creating r-tree index. info 2 dimensional next values:

(1, (1,5)), (19, (6,8)), (20, (3,8)), (4, (1,9)).

the description of info is:

1 info point , nowadays in interval (1,5) 19 info point , nowadays in interval (6,8) 20 info point , nowadays in interval (3,8) 4 info point , nowadays in interval (1,9)

i trying mass load above info r-tree. doing using next test code libspatialindex. however, not getting what should format of input info file passed object *mydatastream stream(argv[1]);*

the test code using is:

// copyright (c) 2002, marios hadjieleftheriou // include library header file. #include <spatialindex/spatialindex.h> using namespace spatialindex; #define insert 1 #define delete 0 #define query 2 class mydatastream : public idatastream { public: mydatastream(std::string inputfile) : m_pnext(0) { m_fin.open(inputfile.c_str()); if (! m_fin) throw tools::illegalargumentexception("input file not found."); readnextentry(); } virtual ~mydatastream() { if (m_pnext != 0) delete m_pnext; } virtual idata* getnext() { if (m_pnext == 0) homecoming 0; rtree::data* ret = m_pnext; m_pnext = 0; readnextentry(); homecoming ret; } virtual bool hasnext() { homecoming (m_pnext != 0); } virtual uint32_t size() { throw tools::notsupportedexception("operation not supported."); } virtual void rewind() { if (m_pnext != 0) { delete m_pnext; m_pnext = 0; } m_fin.seekg(0, std::ios::beg); readnextentry(); } void readnextentry() { id_type id; uint32_t op; double low[2], high[2]; m_fin >> op >> id >> low[0] >> low[1] >> high[0] >> high[1]; if (m_fin.good()) { if (op != insert) throw tools::illegalargumentexception( "the info input should contain insertions only." ); part r(low, high, 2); m_pnext = new rtree::data(sizeof(double), reinterpret_cast<byte*>(low), r, id); // associate bogus info array every entry testing purposes. // 1 time info array given rtree:data local re-create created. // hence, input info array can deleted after operation if not // needed anymore. } } std::ifstream m_fin; rtree::data* m_pnext; }; int main(int argc, char** argv) { seek { if (argc != 5) { std::cerr << "usage: " << argv[0] << " input_file tree_file capacity utilization." << std::endl; homecoming -1; } std::string basename = argv[2]; double utilization = atof(argv[4]); istoragemanager* diskfile = storagemanager::createnewdiskstoragemanager(basename, 4096); // create new storage manager provided base of operations name , 4k page size. storagemanager::ibuffer* file = storagemanager::createnewrandomevictionsbuffer(*diskfile, 10, false); // applies main memory random buffer on top of persistent storage manager // (lru buffer, etc can created same way). mydatastream stream(argv[1]); // create , mass load new rtree dimensionality 2, using "file" // storagemanager , rstar splitting policy. id_type indexidentifier; ispatialindex* tree = rtree::createandbulkloadnewrtree( rtree::blm_str, stream, *file, utilization, atoi(argv[3]), atoi(argv[3]), 2, spatialindex::rtree::rv_rstar, indexidentifier); std::cerr << *tree; std::cerr << "buffer hits: " << file->gethits() << std::endl; std::cerr << "index id: " << indexidentifier << std::endl; bool ret = tree->isindexvalid(); if (ret == false) std::cerr << "error: construction invalid!" << std::endl; else std::cerr << "the stucture seems o.k." << std::endl; delete tree; delete file; delete diskfile; // delete buffer first, storage manager // (otherwise the buffer fail trying write dirty entries). } grab (tools::exception& e) { std::cerr << "******error******" << std::endl; std::string s = e.what(); std::cerr << s << std::endl; homecoming -1; } homecoming 0; }

chop out readnextentry , test that:

void readnextentry(istream& is) { id_type id; uint32_t op; double low[2], high[2]; >> op >> id >> low[0] >> low[1] >> high[0] >> high[1]; }

we can create test input stream using istringstream:

bool isgood(const std::string& input) { std::istringstream ss(input); readnextentry(ss); homecoming ss.good(); }

and demonstrate:

int main() { std::cout << "good? " << isgood("asdf qwer zxcv uyio ghjk") << std::endl; std::cout << "good? " << isgood("0.0 0 0 0 0") << std::endl; std::cout << "good? " << isgood("1 2 3 4 5") << std::endl; }

c++ data-structures r-tree

No comments:

Post a Comment