#include "basics.h"\r
-//#include <cstring>\r
-#include <stack>\r
#include "XMLTree.h"\r
#include "timings.h"\r
#include <errno.h>\r
+using std::cout;\r
+using std::endl;\r
+using std::min;\r
+using std::string;\r
+\r
// functions to convert tag positions to the corresponding tree node and viceversa. \r
// These are implemented in order to be able to change the tree and Tags representations, \r
// without affecting the code so much.\r
XMLTree *XML_Tree;\r
int i;\r
\r
-\r
+ buffer[1023] = '\0';\r
\r
fp = fdopen(fd, "r");\r
\r
PRINTTIME("Loading parenthesis struct", Loading);\r
STARTTIMER();\r
\r
- XML_Tree->TagName = new vector<string>();\r
- XML_Tree->tIdMap = new std::unordered_map<string,int>();\r
- \r
- string s;\r
+ XML_Tree->TagName = new std::vector<std::string>();\r
+ XML_Tree->tIdMap = new std::unordered_map<std::string,int>();\r
+ std::string s;\r
int ntags;\r
\r
// Load the tag names\r
ufread(&ntags, sizeof(int), 1, fp);\r
\r
for (i=0; i<ntags;i++) {\r
- char * r = fgets(buffer,1023,fp);\r
- if (r==NULL)\r
+ if (fgets(buffer,1022,fp) != buffer)\r
throw "Cannot read tag list";\r
- s = (const char*) buffer;\r
+ s = buffer;\r
// remove the trailing \n\r
s.erase(s.size()-1); \r
- XML_Tree->TagName->push_back(s);\r
+ XML_Tree->TagName->push_back(s); \r
XML_Tree->tIdMap->insert(std::make_pair(s,i));\r
\r
};\r
}\r
else return x; \r
}\r
-value XMLTree::CamlFirstElement(value x)\r
-{\r
- return Val_int(FirstElement(Int_val(x)));\r
-}\r
-value XMLTree::CamlNextElement(value x)\r
-{\r
- return Val_int(NextElement(Int_val(x)));\r
-}\r
-\r
-extern "C" value caml_cpp_fast_first_element(value xmltree, value node){\r
- return XMLTREE(xmltree)->CamlFirstElement(node);\r
-}\r
-\r
-extern "C" value caml_cpp_fast_next_element(value xmltree, value node){\r
- return XMLTREE(xmltree)->CamlNextElement(node);\r
-}\r
\r
// LastChild(x): returns the last child of node x.\r
treeNode XMLTree::LastChild(treeNode x)\r
\r
#ifndef XMLTREE_H_\r
#define XMLTREE_H_\r
-extern "C" {\r
-#define CAML_NAME_SPACE\r
-#include <caml/mlvalues.h>\r
-#include <caml/custom.h>\r
-#define XMLTREE(x) ((XMLTree *)(* (XMLTree**) Data_custom_val(x)))\r
- //#define XMLTREE(x) ((XMLTree*) (x))\r
-}\r
+\r
+\r
#include <unordered_set>\r
#include <unordered_map>\r
#include <sstream>\r
#include "TextCollection/TextCollectionBuilder.h"\r
\r
-#include <cstdio>\r
-#include <cstdlib>\r
-#include <cstring>\r
-\r
-\r
#undef W\r
#undef WW\r
#undef Wminusone\r
using SXSI::TextCollectionBuilder;\r
\r
\r
-\r
// this constant is used to efficiently compute the child operation in the tree\r
#define OPTD 10\r
\r
\r
\r
typedef std::unordered_set<int> TagIdSet;\r
-typedef std::unordered_map<string,int> TagIdMap;\r
+typedef std::unordered_map<std::string,int> TagIdMap;\r
typedef TagIdMap::const_iterator TagIdMapIT;\r
\r
#define REGISTER_TAG(v,h,t) do { (h)->insert(std::make_pair((t),(v)->size()));\\r
bp *Par;\r
\r
/** Mapping from tag identifer to tag name */ \r
- vector<string> *TagName;\r
+ std::vector<std::string> *TagName;\r
TagIdMap * tIdMap;\r
\r
/** Bit vector indicating with a 1 the positions of the non-empty texts. */\r
\r
FILE* stream;\r
int stream_fd; \r
- string * buffer;\r
+ std::string * buffer;\r
void myfputs(const char* s, FILE * fp){\r
buffer->append(s);\r
if (buffer->size() >= 100000){\r
XMLTree(){ buffer = 0;};\r
\r
// non const pointer are freed by this method.\r
- XMLTree( pb * const par, uint npar, vector<string> * const TN, TagIdMap * const tim, uint *empty_texts_bmp, TagType *tags,\r
+ XMLTree( pb * const par, uint npar, std::vector<std::string> * const TN, TagIdMap * const tim, uint *empty_texts_bmp, TagType *tags,\r
TextCollection * const TC, bool dis_tc);\r
\r
public: \r
* if none.\r
*/\r
treeNode FirstElement(treeNode x);\r
- value CamlFirstElement(value x);\r
+\r
/** LastChild(x): returns the last child of node x. */\r
treeNode LastChild(treeNode x);\r
\r
* if none.\r
*/\r
treeNode NextElement(treeNode x);\r
- value CamlNextElement(value x);\r
+\r
/** PrevSibling(x): returns the previous sibling of node x, assuming it \r
* exists. */\r
\r
\r
};\r
\r
-extern "C" value caml_cpp_fast_first_element(value xmltree, value node);\r
-extern "C" value caml_cpp_fast_next_element(value xmltree, value node);\r
\r
\r
\r
#include "basics.h"\r
#include "XMLTreeBuilder.h"\r
#include "timings.h"\r
+using std::string;\r
\r
XMLTreeBuilder::~XMLTreeBuilder(){\r
\r
#ifndef XMLTREEBUILDER_H_\r
#define XMLTREEBUILDER_H_\r
\r
-#include <cstdlib>\r
-#include <cstdio>\r
-#include <cstring>\r
-#include <unordered_map>\r
#include "TextCollection/TextCollectionBuilder.h"\r
#undef W\r
#undef WW\r
\r
\r
#include "XMLTree.h"\r
-#include "bp.h"\r
-#include <static_bitsequence.h>\r
-#include <alphabet_mapper.h>\r
-#include <static_sequence.h>\r
\r
using SXSI::TextCollection;\r
using SXSI::TextCollectionBuilder;\r
int npar;\r
\r
/** Mapping from tag identifer to tag name */ \r
- vector<string> *TagName;\r
+ std::vector<std::string> *TagName;\r
TagIdMap * tIdMap;\r
/** Array containing the sequence of tags */\r
TagType *tags_aux;\r
\r
/** The texts in the XML document (cached for faster display) */\r
\r
- vector<string> *CachedText;\r
+ std::vector<std::string> *CachedText;\r
\r
unsigned int *empty_texts_aux;\r
int eta_size;\r
/** NewOpenTag(tagname): indicates the event of finding a new opening tag \r
* in the document. Tag name is given. Returns a non-zero value upon \r
* success, and returns NULLT in case of error. */\r
- int NewOpenTag(string tagname);\r
+ int NewOpenTag(std::string tagname);\r
\r
/** NewClosingTag(tagname): indicates the event of finding a new closing tag\r
* in the document. Tag name is given. Returns a non-zero value upon \r
* success, and returns NULLT in case of error. */\r
- int NewClosingTag(string tagname);\r
+ int NewClosingTag(std::string tagname);\r
\r
/** NewText(s): indicates the event of finding a new text s in \r
* the document. The new text is inserted within the text collection. \r
* the string the sequence '\0x01\0x00' is inserted in the TextCollection\r
* It is ok to do so since a non printable character cannot occur in an XML document\r
*/\r
- int NewText(string text);\r
+ int NewText(std::string text);\r
\r
\r
};\r
-#ifndef BASICS_H\r
-#define BASICS_H\r
+#ifndef BASICS_H_\r
+#define BASICS_H_\r
+\r
\r
-#include <string>\r
#include <stdio.h>\r
#include <stdlib.h>\r
-#include <string.h> // for memset\r
+//#include <string.h> // for memset\r
#include <sys/types.h>\r
#include <unistd.h>\r
#include <errno.h>\r
-\r
+#define B_ERROR(msg) do { fprintf(stderr,"%s\n", msg); exit(1); } while (0)\r
\r
inline void ufread(void *ptr, size_t size, size_t nmemb, FILE *stream)\r
{\r
size_t res;\r
res = fread(ptr,size,nmemb,stream);\r
if (res < nmemb)\r
- throw ("ufread I/O error" );\r
+ B_ERROR ("ufread I/O error" );\r
return;\r
}\r
\r
size_t res;\r
res = fwrite(ptr,size,nmemb,stream);\r
if (res < nmemb)\r
- throw "ufwrite I/O error";\r
+ B_ERROR("ufwrite I/O error");\r
return;\r
}\r
\r
void *dest = realloc(ptr,size);\r
//don't fail if we requested size 0\r
if (dest == NULL && size > 0 )\r
- throw std::bad_alloc();\r
+ B_ERROR("urealoc error");\r
return dest;\r
}\r
// realloc and set to 0\r
void *dest = realloc(ptr,n_size);\r
//don't fail if we requested size 0\r
if (dest == NULL && n_size > 0 )\r
- throw std::bad_alloc();\r
+ B_ERROR("urecalloc error");\r
// Initialize the new area with 0\r
void * n_area_start = &(((char*) dest)[o_size]);\r
- memset(n_area_start,0, n_size - o_size);\r
+ // memset(n_area_start,0, n_size - o_size);\r
+ for(size_t i = 0; i < n_size - o_size;i++)\r
+ ((char *) n_area_start)[i] = 0;\r
return dest;\r
}\r
\r
void * dest = calloc(nmemb,size);\r
//don't fail if we requested size 0\r
if (dest == NULL && nmemb > 0 && size > 0 )\r
- throw std::bad_alloc();\r
+ B_ERROR("ucalloc error");\r
return dest;\r
}\r
\r
{\r
void * dest = malloc(size);\r
if (dest == NULL && size > 0)\r
- throw std::bad_alloc();\r
+ B_ERROR("umaloc error");\r
return dest;\r
}\r
\r
#include "bp.h"\r
+#include <algorithm>\r
+using std::min;\r
+using std::max;\r
\r
//#define CHECK\r
#define RANDOM\r
int childtbl[(ETW)*(1<<ETW)];\r
int childtbl2[2*ETW+1][ETW][(1<<ETW)];\r
int depthtbl[(2*ETW+1)*(1<<ETW)];\r
-\r
+int inited = 0;\r
void make_matchtbl(void)\r
{\r
int i,j,x,r;\r
int m,M;\r
pb buf[1];\r
int deg;\r
-\r
+ if (inited)\r
+ return;\r
+ inited = 1;\r
for (x = 0; x < (1<<ETW); x++) {\r
setbits(buf,0,ETW,x);\r
for (r=-ETW; r<=ETW; r++) fwdtbl[((r+ETW)<<ETW)+x] = ETW;\r
#define ETW 8 // width of excess lookup table
#define W1 2 // branching factor
-#ifndef min
- #define min(x,y) ((x)<(y)?(x):(y))
-#endif
-#ifndef max
- #define max(x,y) ((x)>(y)?(x):(y))
-#endif
typedef struct {
extern int depthtbl[(2*ETW+1)*(1<<ETW)];
extern int childtbl2[2*ETW+1][ETW][(1<<ETW)];
+
#endif
#include <stdio.h>
#include <stdlib.h>
#include "bp.h"
+#ifndef min
+ #define min(x,y) ((x)<(y)?(x):(y))
+#endif
+#ifndef max
+ #define max(x,y) ((x)>(y)?(x):(y))
+#endif
#define NOTFOUND -2
#define CONTINUE -3
-all: clean libcompact tests
+all: clean libcompact
doc:
#include <sys/stat.h>
#include <iostream>
#include <iostream>
-using namespace std;
+////using namespace std;
#include <cstdlib>
#include <cmath>
*/
#include <huffman_codes.h>
+using std::max;
huffman_codes::huffman_codes(uint * symb, uint n) {
uint max_v = 0;
#include <sdarray.h>
-
+using std::min;
+using std::max;
#if 0
typedef unsigned int qword;
#define logD 4
#include <iostream>
-using namespace std;
+//using namespace std;
/** Base class for static bitsequences, contains many abstract functions, so this can't
* be instantiated. It includes base implementations for rank0, select0 and select1 based
#include <cassert>
#include <cmath>
// #include <sys/types.h>
-
+using std::cout;
+using std::endl;
/////////////
//Rank(B,i)//
*/
#include <static_bitsequence_rrr02.h>
-
+using std::min;
+using std::max;
table_offset * static_bitsequence_rrr02::E = NULL;
static_bitsequence_rrr02::static_bitsequence_rrr02() {
#include <cassert>
#include <iostream>
-using namespace std;
+//using namespace std;
/** Implementation of Raman, Raman and Rao's [1] proposal for rank/select capable
* data structures, it achieves space nH_0, O(sample_rate) time for rank and O(log len)
*/
#include <static_bitsequence_rrr02_light.h>
-
+using std::min;
+using std::max;
#define VARS_NEEDED uint C_len = len/BLOCK_SIZE_LIGHT + (len%BLOCK_SIZE_LIGHT!=0);\
uint C_field_bits = bits(BLOCK_SIZE_LIGHT);\
uint O_len = uint_len(1,O_bits_len);\
#include <cassert>
#include <iostream>
-using namespace std;
+//using namespace std;
/** Implementation of Raman, Raman and Rao's [1] proposal for rank/select capable
* data structures, it achieves space nH_0, O(sample_rate) time for rank and O(log len)
#include <basics.h>
#include <iostream>
-using namespace std;
+//using namespace std;
/** Universal table required for static_bitsequence_rrr02, Raman, Raman and Rao's [1]
* proposal for rank/select capable data structures, it achieves space nH_0,
*/
#include <static_sequence.h>
+using std::max;
+using std::min;
+using std::cout;
+using std::cin;
+using std::endl;
+
static_sequence::static_sequence() {}
static_sequence::~static_sequence() {}
#include <basics.h>
#include <iostream>
#include <vector>
-
+using std::vector;
#define WVTREE_HDR 2
#define GMR_CHUNK_HDR 3
#define GMR_HDR 4
#define WVTREE_NOPTRS_HDR 5
#define BS_HDR 6
-using namespace std;
+//using namespace std;
/** Base class for static sequences, contains many abstract functions, so this can't
* be instantiated.
#include <static_sequence_bs.h>
-
+using std::max;
static_sequence_bs::static_sequence_bs(uint * seq, uint n, alphabet_mapper * am, static_bitsequence_builder * bmb) {
sigma = 0;
len = n;
*/
#include <static_sequence_gmr.h>
-
+using std::max;
static_sequence_gmr::static_sequence_gmr(uint * sequence, uint n, uint chunk_length, static_bitsequence_builder * bmb, static_sequence_builder * ssb) {
len = n;
if(len%chunk_length) len+=chunk_length-len%chunk_length;
#include <cassert>
#include <iostream>
-using namespace std;
+//using namespace std;
class static_sequence_gmr : public static_sequence {
public:
*/
#include "static_sequence_gmr_chunk.h"
+using std::max;
static_sequence_gmr_chunk::static_sequence_gmr_chunk(uint * sequence, uint chunk_length, static_bitsequence_builder *bmb, static_permutation_builder *pmb) {
sigma = 0;
#include <cassert>
#include <iostream>
-using namespace std;
+//using namespace std;
/** Implementation of the Chunk of Golynski et al's rank/select
* data structure [1].
#include <alphabet_mapper.h>
#include <static_sequence.h>
-using namespace std;
+//using namespace std;
/** Wavelet tree implementation using pointers.
*
*/
#include <static_sequence_wvtree_noptrs.h>
-
+using std::min;
+using std::max;
static_sequence_wvtree_noptrs::static_sequence_wvtree_noptrs(uint * symbols, uint n, static_bitsequence_builder * bmb, alphabet_mapper * am, bool deleteSymbols) {
this->n=n;
this->am=am;
#include <static_sequence.h>
#include <alphabet_mapper.h>
-using namespace std;
+//using namespace std;
class static_sequence_wvtree_noptrs : public static_sequence {
public:
#include <basics.h>
#include <iostream>
-using namespace std;
+//using namespace std;
#define WT_CODER_HUFF_HDR 2
#define WT_CODER_BINARY_HDR 3
*/
#include <wt_coder_binary.h>
-
+using std::min;
+using std::max;
wt_coder_binary::wt_coder_binary(uint * seq, uint n, alphabet_mapper * am) {
uint max_v = 0;
for(uint i=0;i<n;i++)
#include <static_bitsequence.h>
#include <static_bitsequence_builder.h>
#include <cassert>
+using std::vector;
/** Clase for representing internal nodes
*
#define ALPHABET_MAPPER_NONE_HDR 2
#define ALPHABET_MAPPER_CONT_HDR 3
-using namespace std;
+//using namespace std;
/** Base class for alphabet mappers
*
*/
#include <alphabet_mapper_cont.h>
-
+using std::max;
alphabet_mapper_cont::alphabet_mapper_cont(uint * seq, uint n, static_bitsequence_builder *bmb) {
uint max_v = 0;
for(uint i=0;i<n;i++)
#include <static_bitsequence.h>
#include <static_bitsequence_builder.h>
-using namespace std;
+//using namespace std;
/** Mapper that doesn't change the value (identity)
*
#include <iostream>
#include <alphabet_mapper.h>
-using namespace std;
+//using namespace std;
/** Mapper that doesn't change the value (identity)
*
#include <static_sequence.h>
#include <static_sequence_builder.h>
#include "static_sequence_tester.h"
+using namespace std;
int main(int argc, char ** argv) {
if(argc!=6) {
-FLAGS =-std=c++0x -O3 -I./libcds/includes/ -I. -fno-PIC\r
+CFLAGS= -g -O0 -I./libcds/includes/ -I.\r
+FLAGS= -std=c++0x $(CFLAGS)\r
\r
LIBCDS_A=libcds/lib/libcds.a \r
OBJECTS_TCO= TextCollection/TextCollection.o TextCollection/TextCollectionBuilder.o TextCollection/TCImplementation.o TextCollection/Tools.o TextCollection/BitRank.o TextCollection/TextStorage.o\r
static struct timeval tmpv1;
static struct timeval tmpv2;
-static string mem1;
-static string mem2;
+static std::string mem1;
+static std::string mem2;
-static void read_procmem(string& memstr) {
+static void read_procmem(std::string& memstr) {
std::string buf;
pid_t pid = getpid();
std::stringstream path;