├── Build.cpp ├── FMIndex ├── SSA.cpp ├── SSA.h ├── SuffixArray.cpp └── SuffixArray.h ├── Hash ├── Hash.cpp ├── Hash.h ├── HashBBdh.cpp ├── HashBBdh.h ├── HashBdh.cpp ├── HashBdh.h ├── HashDAC.cpp ├── HashDAC.h ├── HashUtils.h ├── Hashdh.cpp └── Hashdh.h ├── HuTucker ├── HuTucker.cpp └── HuTucker.h ├── Huffman ├── Huffman.cpp ├── Huffman.h ├── huff.cpp └── huff.h ├── LICENSE.md ├── Makefile ├── README ├── RePair ├── Coder │ ├── CRePair.cpp │ ├── CRePair.h │ ├── DRePair.o │ ├── IRePair.cpp │ ├── IRePair.h │ ├── arrayg.cpp │ ├── arrayg.h │ ├── basics.cpp │ ├── basics.h │ ├── dictionary.cpp │ ├── dictionary.h │ ├── hash.cpp │ ├── hash.h │ ├── heap.cpp │ ├── heap.h │ ├── records.cpp │ └── records.h ├── RePair.cpp └── RePair.h ├── StringDictionary.cpp ├── StringDictionary.h ├── StringDictionaryFMINDEX.cpp ├── StringDictionaryFMINDEX.h ├── StringDictionaryHASHHF.cpp ├── StringDictionaryHASHHF.h ├── StringDictionaryHASHRPDAC.cpp ├── StringDictionaryHASHRPDAC.h ├── StringDictionaryHASHRPF.cpp ├── StringDictionaryHASHRPF.h ├── StringDictionaryHASHUFFDAC.cpp ├── StringDictionaryHASHUFFDAC.h ├── StringDictionaryHHTFC.cpp ├── StringDictionaryHHTFC.h ├── StringDictionaryHTFC.cpp ├── StringDictionaryHTFC.h ├── StringDictionaryPFC.cpp ├── StringDictionaryPFC.h ├── StringDictionaryRPDAC.cpp ├── StringDictionaryRPDAC.h ├── StringDictionaryRPFC.cpp ├── StringDictionaryRPFC.h ├── StringDictionaryRPHTFC.cpp ├── StringDictionaryRPHTFC.h ├── StringDictionaryXBW.cpp ├── StringDictionaryXBW.h ├── Test.cpp ├── XBW ├── TrieNode.cpp ├── TrieNode.h ├── XBW.cpp └── XBW.h ├── iterators ├── IteratorDictID.h ├── IteratorDictIDContiguous.h ├── IteratorDictIDDuplicates.h ├── IteratorDictIDNoContiguous.h ├── IteratorDictIDXBW.h ├── IteratorDictIDXBWDuplicates.h ├── IteratorDictString.h ├── IteratorDictStringFMINDEX.h ├── IteratorDictStringFMINDEXDuplicates.h ├── IteratorDictStringHHTFC.h ├── IteratorDictStringHTFC.h ├── IteratorDictStringPFC.h ├── IteratorDictStringPlain.h ├── IteratorDictStringRPDAC.h ├── IteratorDictStringRPFC.h ├── IteratorDictStringRPHTFC.h ├── IteratorDictStringVector.h ├── IteratorDictStringXBW.h └── IteratorDictStringXBWDuplicates.h ├── libcds ├── COPYRIGHT ├── Changelog ├── Doxyfile ├── Makefile ├── docs │ └── delete_me ├── includes │ └── delete_me ├── lib │ └── delete_me ├── src │ ├── Makefile │ ├── static │ │ ├── bitsequence (copia) │ │ │ ├── BitSequence.cpp │ │ │ ├── BitSequence.h │ │ │ ├── BitSequenceBuilder.h │ │ │ ├── BitSequenceBuilderDArray.cpp │ │ │ ├── BitSequenceBuilderDArray.h │ │ │ ├── BitSequenceBuilderRG.cpp │ │ │ ├── BitSequenceBuilderRG.h │ │ │ ├── BitSequenceBuilderRRR.cpp │ │ │ ├── BitSequenceBuilderRRR.h │ │ │ ├── BitSequenceBuilderSDArray.cpp │ │ │ ├── BitSequenceBuilderSDArray.h │ │ │ ├── BitSequenceDArray.cpp │ │ │ ├── BitSequenceDArray.h │ │ │ ├── BitSequenceRG.cpp │ │ │ ├── BitSequenceRG.h │ │ │ ├── BitSequenceRRR.cpp │ │ │ ├── BitSequenceRRR.h │ │ │ ├── BitSequenceSDArray.cpp │ │ │ ├── BitSequenceSDArray.h │ │ │ ├── Makefile │ │ │ ├── TableOffsetRRR.cpp │ │ │ ├── TableOffsetRRR.h │ │ │ ├── sdarraySadakane.cpp │ │ │ └── sdarraySadakane.h │ │ ├── bitsequence │ │ │ ├── BitSequence.cpp │ │ │ ├── BitSequence.h │ │ │ ├── BitSequence375.cpp │ │ │ ├── BitSequence375.h │ │ │ ├── BitSequenceBuilder.h │ │ │ ├── BitSequenceBuilder375.cpp │ │ │ ├── BitSequenceBuilder375.h │ │ │ ├── BitSequenceBuilderDArray.cpp │ │ │ ├── BitSequenceBuilderDArray.h │ │ │ ├── BitSequenceBuilderRG.cpp │ │ │ ├── BitSequenceBuilderRG.h │ │ │ ├── BitSequenceBuilderRRR.cpp │ │ │ ├── BitSequenceBuilderRRR.h │ │ │ ├── BitSequenceBuilderSDArray.cpp │ │ │ ├── BitSequenceBuilderSDArray.h │ │ │ ├── BitSequenceDArray.cpp │ │ │ ├── BitSequenceDArray.h │ │ │ ├── BitSequenceRG.cpp │ │ │ ├── BitSequenceRG.h │ │ │ ├── BitSequenceRRR.cpp │ │ │ ├── BitSequenceRRR.h │ │ │ ├── BitSequenceSDArray.cpp │ │ │ ├── BitSequenceSDArray.h │ │ │ ├── Makefile │ │ │ ├── TableOffsetRRR.cpp │ │ │ ├── TableOffsetRRR.h │ │ │ ├── sdarraySadakane.cpp │ │ │ └── sdarraySadakane.h │ │ ├── coders │ │ │ ├── Coder.h │ │ │ ├── HuffmanCoder.cpp │ │ │ ├── HuffmanCoder.h │ │ │ ├── Makefile │ │ │ ├── huff.cpp │ │ │ └── huff.h │ │ ├── mapper │ │ │ ├── Makefile │ │ │ ├── Mapper.cpp │ │ │ ├── Mapper.h │ │ │ ├── MapperCont.cpp │ │ │ ├── MapperCont.h │ │ │ ├── MapperNone.cpp │ │ │ └── MapperNone.h │ │ ├── permutation │ │ │ ├── Makefile │ │ │ ├── Permutation.cpp │ │ │ ├── Permutation.h │ │ │ ├── PermutationBuilder.h │ │ │ ├── PermutationBuilderMRRR.cpp │ │ │ ├── PermutationBuilderMRRR.h │ │ │ ├── PermutationMRRR.cpp │ │ │ ├── PermutationMRRR.h │ │ │ ├── perm.cpp │ │ │ └── perm.h │ │ ├── sequence │ │ │ ├── .WaveletTree.cpp.swp │ │ │ ├── .WaveletTree.h.swp │ │ │ ├── .wt_node_internal.cpp.swp │ │ │ ├── .wt_node_internal.h.swp │ │ │ ├── .wt_node_leaf.cpp.swp │ │ │ ├── BitmapsSequence.cpp │ │ │ ├── BitmapsSequence.h │ │ │ ├── Makefile │ │ │ ├── Sequence.cpp │ │ │ ├── Sequence.h │ │ │ ├── SequenceAlphPart.cpp │ │ │ ├── SequenceAlphPart.h │ │ │ ├── SequenceBuilder.h │ │ │ ├── SequenceBuilderAlphPart.cpp │ │ │ ├── SequenceBuilderAlphPart.h │ │ │ ├── SequenceBuilderGMR.cpp │ │ │ ├── SequenceBuilderGMR.h │ │ │ ├── SequenceBuilderGMRChunk.cpp │ │ │ ├── SequenceBuilderGMRChunk.h │ │ │ ├── SequenceBuilderStr.cpp │ │ │ ├── SequenceBuilderStr.h │ │ │ ├── SequenceBuilderWaveletTree.cpp │ │ │ ├── SequenceBuilderWaveletTree.h │ │ │ ├── SequenceBuilderWaveletTreeNoptrs.cpp │ │ │ ├── SequenceBuilderWaveletTreeNoptrs.h │ │ │ ├── SequenceGMR.cpp │ │ │ ├── SequenceGMR.h │ │ │ ├── SequenceGMRChunk.cpp │ │ │ ├── SequenceGMRChunk.h │ │ │ ├── WaveletTree.cpp │ │ │ ├── WaveletTree.h │ │ │ ├── WaveletTreeNoptrs.cpp │ │ │ ├── WaveletTreeNoptrs.h │ │ │ ├── wt_coder.cpp │ │ │ ├── wt_coder.h │ │ │ ├── wt_coder_binary.cpp │ │ │ ├── wt_coder_binary.h │ │ │ ├── wt_coder_huff.cpp │ │ │ ├── wt_coder_huff.h │ │ │ ├── wt_node.cpp │ │ │ ├── wt_node.h │ │ │ ├── wt_node_internal.cpp │ │ │ ├── wt_node_internal.h │ │ │ ├── wt_node_leaf.cpp │ │ │ └── wt_node_leaf.h │ │ ├── suffixtree │ │ │ ├── LCP.cpp │ │ │ ├── LCP.h │ │ │ ├── LCP_DAC.cpp │ │ │ ├── LCP_DAC.h │ │ │ ├── LCP_DAC_VAR.cpp │ │ │ ├── LCP_DAC_VAR.h │ │ │ ├── LCP_FMN.cpp │ │ │ ├── LCP_FMN.h │ │ │ ├── LCP_PT.cpp │ │ │ ├── LCP_PT.h │ │ │ ├── LCP_PhiSpare.cpp │ │ │ ├── LCP_PhiSpare.h │ │ │ ├── LCP_Sad.cpp │ │ │ ├── LCP_Sad.h │ │ │ ├── LCP_naive.cpp │ │ │ ├── LCP_naive.h │ │ │ ├── Makefile │ │ │ ├── NPR.cpp │ │ │ ├── NPR.h │ │ │ ├── NPR_CN.cpp │ │ │ ├── NPR_CN.h │ │ │ ├── NPR_FMN.cpp │ │ │ ├── NPR_FMN.h │ │ │ ├── NSV.cpp │ │ │ ├── NSV.h │ │ │ ├── PSV.cpp │ │ │ ├── PSV.h │ │ │ ├── RMQ_succinct.cpp │ │ │ ├── RMQ_succinct.h │ │ │ ├── RMQ_succinct_lcp.cpp │ │ │ ├── RMQ_succinct_lcp.h │ │ │ ├── SuffixTree.cpp │ │ │ ├── SuffixTree.h │ │ │ ├── SuffixTreeY.cpp │ │ │ ├── SuffixTreeY.h │ │ │ ├── factorization.cpp │ │ │ ├── factorization.h │ │ │ ├── factorization_var.cpp │ │ │ └── factorization_var.h │ │ └── textindex │ │ │ ├── Makefile │ │ │ ├── TextIndex.cpp │ │ │ ├── TextIndex.h │ │ │ ├── TextIndexCSA.cpp │ │ │ ├── TextIndexCSA.h │ │ │ ├── comparray4.cpp │ │ │ ├── comparray4.h │ │ │ ├── interface.h │ │ │ ├── mmap.cpp │ │ │ ├── mmap.h │ │ │ ├── qsufsort.cpp │ │ │ └── suftest3.test.cpp │ └── utils │ │ ├── Array.cpp │ │ ├── Array.h │ │ ├── BitString.cpp │ │ ├── BitString.h │ │ ├── Makefile │ │ ├── cppUtils.cpp │ │ ├── cppUtils.h │ │ ├── libcdsBasics.h │ │ ├── libcdsSDArray.h │ │ └── libcdsTrees.h └── tests │ ├── Makefile │ ├── runTests.py │ ├── testArray.cpp │ ├── testBitSequence.cpp │ ├── testHuffman.cpp │ ├── testLCP.cpp │ ├── testNPR.cpp │ ├── testSequence.cpp │ ├── testSuffixTree.cpp │ └── testTextIndex.cpp └── utils ├── Coder ├── BinaryNode.cpp ├── BinaryNode.h ├── Coder.cpp ├── Coder.h ├── Codeword.h ├── DecodingTable.cpp ├── DecodingTable.h ├── DecodingTableBuilder.cpp ├── DecodingTableBuilder.h ├── DecodingTree.cpp ├── DecodingTree.h ├── StatCoder.cpp └── StatCoder.h ├── DAC_BVLS.cpp ├── DAC_BVLS.h ├── DAC_VLS.cpp ├── DAC_VLS.h ├── LogSequence.cpp ├── LogSequence.h ├── Utils.h ├── VByte.cpp └── VByte.h /Hash/HashUtils.h: -------------------------------------------------------------------------------- 1 | /* HashUtils.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * Utilities for compressed hash dictionaries. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 | * Contacting the authors: 23 | * Francisco Claude: fclaude@recoded.cl 24 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 25 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 26 | */ 27 | 28 | 29 | #ifndef _HASHUTILS_H 30 | #define _HASHUTILS_H 31 | 32 | struct SortString { 33 | size_t original; // Original string position in Tdict 34 | size_t hash; // String position in the hash table 35 | }; 36 | 37 | /* Bitwise hash function. Note that tsize does not have to be prime. */ 38 | inline size_t 39 | bitwisehash(uchar *word, size_t len, size_t htsize) 40 | { 41 | uint h = (uint)(4294967279u); 42 | int c; 43 | for(size_t i= 0; i> 27)) ^ word[i]; 58 | } 59 | h = h%(htsize-1); 60 | if(h==0) 61 | return 1; 62 | return (size_t)h; 63 | } 64 | 65 | /*compute the first prime number higher or equal to n*/ 66 | inline size_t 67 | nearest_prime(size_t n) 68 | { 69 | size_t prime = n; 70 | size_t sqrt_prime, i; 71 | /*we will supose that prime will not be longer than the maximum unsigned int value*/ 72 | while(true){ 73 | if(prime%2 !=0){ 74 | sqrt_prime = (size_t)(sqrt(prime)+1); 75 | for(i=3; i=sqrt_prime) 80 | return prime; 81 | } 82 | prime++; 83 | } 84 | return prime; 85 | } 86 | 87 | #endif /* _HASHUTILS_H */ 88 | 89 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CPP=g++ 2 | FLAGS=-O9 -Wall -DNDEBUG -I libcds/includes/ 3 | LIB=libcds/lib/libcds.a 4 | 5 | OBJECTS_CODER=utils/Coder/StatCoder.o utils/Coder/DecodingTableBuilder.o utils/Coder/DecodingTable.o utils/Coder/DecodingTree.o utils/Coder/BinaryNode.o 6 | OBJECTS_UTILS=utils/VByte.o utils/LogSequence.o utils/DAC_VLS.o utils/DAC_BVLS.o $(OBJECTS_CODER) 7 | 8 | OBJECTS_HUTUCKER=HuTucker/HuTucker.o 9 | OBJECTS_REPAIR=RePair/Coder/arrayg.o RePair/Coder/basics.o RePair/Coder/hash.o RePair/Coder/heap.o RePair/Coder/records.o RePair/Coder/dictionary.o RePair/Coder/IRePair.o RePair/Coder/CRePair.o RePair/RePair.o 10 | OBJECTS_HASH=Hash/Hash.o Hash/HashDAC.o Hash/Hashdh.o Hash/HashBdh.o Hash/HashBBdh.o 11 | OBJECTS_HUFFMAN=Huffman/huff.o Huffman/Huffman.o 12 | OBJECTS_FMINDEX=FMIndex/SuffixArray.o FMIndex/SSA.o 13 | OBJECTS_XBW=XBW/TrieNode.o XBW/XBW.o 14 | OBJECTS=$(OBJECTS_UTILS) $(OBJECTS_HUTUCKER) $(OBJECTS_HUFFMAN) $(OBJECTS_REPAIR) $(OBJECTS_HASH) $(OBJECTS_XBW) $(OBJECTS_FMINDEX) StringDictionary.o StringDictionaryHASHHF.o StringDictionaryHASHRPF.o StringDictionaryHASHUFFDAC.o StringDictionaryHASHRPDAC.o StringDictionaryPFC.o StringDictionaryRPFC.o StringDictionaryHTFC.o StringDictionaryHHTFC.o StringDictionaryRPHTFC.o StringDictionaryRPDAC.o StringDictionaryXBW.o StringDictionaryFMINDEX.o 15 | EXES=Build.o Test.o 16 | 17 | BIN=Build Test 18 | 19 | %.o: %.cpp 20 | @echo " [C++] Compiling $<" 21 | @$(CPP) $(FLAGS) -c $< -o $@ 22 | 23 | all: clean $(OBJECTS) $(EXES) $(BIN) 24 | @echo " [MSG] Done compiling tests" 25 | @echo " [FLG] $(FLAGS)" 26 | 27 | Build: 28 | $(CPP) $(FLAGS) -o Build Build.o $(OBJECTS) ${LIB} 29 | 30 | Test: 31 | $(CPP) $(FLAGS) -o Test Test.o $(OBJECTS) ${LIB} 32 | 33 | 34 | clean: 35 | @echo " [CLN] Removing object files" 36 | @rm -f $(BIN) $(OBJECTS) $(EXES) *~ iterators/*~ FMIndex/*~ Hash/*~ Huffman/*~ RePair/*~ utils/*~ XBW/*~ 37 | 38 | -------------------------------------------------------------------------------- /RePair/Coder/CRePair.h: -------------------------------------------------------------------------------- 1 | /* CRePair.h 2 | Copyright (C) 2007, Rodrigo Gonzalez, Francisco Claude F, all rights reserved. 3 | 4 | Compressed RePair 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | */ 21 | 22 | #ifndef CREPAIR_H 23 | #define CREPAIR_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | using namespace cds_utils; 35 | using namespace cds_static; 36 | 37 | using namespace std; 38 | 39 | class CRePair { 40 | 41 | public: 42 | CRePair(); 43 | 44 | void compress(uint min_value, uint max_value, uint max_assigned, uint m, uint n, uint *symbols, uint *symbols_pair); 45 | 46 | uint* getSequence(); 47 | Array* getSymbolsGrammar(); 48 | BitSequence* getBitsGrammar(); 49 | 50 | ~CRePair(); 51 | 52 | protected: 53 | uint min_value, max_value, max_assigned, m, n, pos, symbols_new_len; 54 | uint *symbols, *symbols_pair, *symbols_new, *symbols_new_bit; 55 | Array * final_symbols_dict; 56 | BitSequence *BRR; 57 | 58 | bool compress_pair_table(); 59 | void fillBR(); 60 | void unroll(uint s, uint i); 61 | void new_value(uint *symbols_pair, uint *symbols_new_value, uint *k1, uint *j, uint pos); 62 | }; 63 | 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /RePair/Coder/DRePair.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/RePair/Coder/DRePair.o -------------------------------------------------------------------------------- /RePair/Coder/IRePair.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Repair -- an implementation of Larsson and Moffat's compression and 4 | decompression algorithms. 5 | Copyright (C) 2010-current_year Gonzalo Navarro 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 22 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 23 | 24 | */ 25 | 26 | // extendible array for records 27 | 28 | #ifndef IREPAIR 29 | #define IREPAIR 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "basics.h" 39 | #include "records.h" 40 | #include "hash.h" 41 | #include "heap.h" 42 | #include "dictionary.h" 43 | 44 | static const int PRNC = 0; 45 | static const int PRNR = 0; 46 | static const int PRNP = 0; 47 | static const int PRNL = 0; 48 | // to avoid many reallocs at small sizes, should be ok as is 49 | static const int minsize = 256; 50 | 51 | class IRePair 52 | { 53 | public: 54 | IRePair(){}; 55 | int compress(int *text, unsigned int length, size_t *csymbols, size_t *crules, Tdiccarray **rules); 56 | 57 | private: 58 | int u; // |text| and later current |C| with gaps 59 | int *C; // compressed text 60 | int c; // real |C| 61 | int alph; // max used terminal symbol 62 | int n; // |R| 63 | Tlist *L; // |L| = c; 64 | Thash Hash; // hash table of pairs 65 | Theap Heap; // special heap of pairs 66 | Trarray Rec; // records 67 | Tdiccarray Dicc; // compressed dictionary 68 | 69 | int repair(); 70 | int expand (int i, int d); 71 | 72 | void prepare(int len); 73 | void prnSym(int c); 74 | void prnC(void); 75 | void prnRec(void); 76 | }; 77 | #endif 78 | 79 | 80 | -------------------------------------------------------------------------------- /RePair/Coder/arrayg.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Repair -- an implementation of Larsson and Moffat's compression and 4 | decompression algorithms. 5 | Copyright (C) 2010-current_year Gonzalo Navarro 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 22 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 23 | 24 | */ 25 | 26 | // extendible circular array for pairs 27 | 28 | #ifndef ARRAYINCLUDED 29 | #define ARRAYINCLUDED 30 | 31 | #include "basics.h" 32 | 33 | typedef struct 34 | { int *pairs; // identifiers 35 | int maxsize; 36 | int size; 37 | int fst; // first of circular array 38 | float factor; 39 | int minsize; 40 | void *Rec; // records 41 | } Tarray; 42 | 43 | // contents can be accessed as A.pairs[0..A.size-1] 44 | class ArrayG 45 | { 46 | public: 47 | // creates empty array 48 | static Tarray createArray (void *Rec, float factor, int minsize); 49 | // destroys A 50 | static void destroyArray (Tarray *A); 51 | 52 | // inserts pair in A, returns pos 53 | static int insertArray (Tarray *A, int pair); 54 | // deletes last cell in A 55 | static void deleteArray (Tarray *A); 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /RePair/Coder/basics.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Repair -- an implementation of Larsson and Moffat's compression and 5 | decompression algorithms. 6 | Copyright (C) 2010-current_year Gonzalo Navarro 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | 22 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 23 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | int NullFreq = 1 << (8*sizeof(int)-1); 31 | 32 | void *myMalloc (long long n) 33 | { 34 | void *p; 35 | if (n == 0) return NULL; 36 | p = (void*)malloc(n); 37 | if (p == NULL) 38 | { fprintf(stderr,"Error: malloc failed\n"); 39 | exit(1); 40 | } 41 | return p; 42 | } 43 | 44 | void *myRealloc (void *p, long long n) 45 | { 46 | if (n == 0) { free(p); return NULL; } 47 | if (p == NULL) return myMalloc(n); 48 | p = (void*)realloc(p,n); 49 | if (p == NULL) 50 | { fprintf(stderr,"Error: realloc failed\n"); 51 | exit(1); 52 | } 53 | return p; 54 | } 55 | 56 | int blog (int x) 57 | { 58 | int l=0; 59 | while (x) { x>>=1; l++; } 60 | return l; 61 | } 62 | -------------------------------------------------------------------------------- /RePair/Coder/basics.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Repair -- an implementation of Larsson and Moffat's compression and 5 | decompression algorithms. 6 | Copyright (C) 2010-current_year Gonzalo Navarro 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | 22 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 23 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 24 | 25 | */ 26 | 27 | #ifndef BASICSINCLUDED 28 | #define BASICSINCLUDED 29 | 30 | void *myMalloc (long long n); // safe malloc/realloc 31 | void *myRealloc (void *p, long long n); 32 | 33 | #define malloc(n) myMalloc(n) 34 | #define realloc(p,n) myRealloc(p,n) 35 | 36 | typedef struct 37 | { int left,right; 38 | } Tpair; 39 | 40 | extern int NullFreq; 41 | 42 | int blog (int x); // bits to represent x 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /RePair/Coder/dictionary.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Repair -- an implementation of Larsson and Moffat's compression and 5 | decompression algorithms. 6 | Copyright (C) 2010-current_year Gonzalo Navarro 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | 22 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 23 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 24 | 25 | */ 26 | 27 | // extendible array for rules 28 | 29 | #include 30 | #include "dictionary.h" 31 | 32 | int 33 | Dictionary::insertRule (Tdiccarray *Dicc, Trule rule) 34 | { int id; 35 | Trule *nrule; 36 | if (Dicc->size == Dicc->maxsize) 37 | { if (Dicc->maxsize == 0) 38 | { Dicc->maxsize = Dicc->minsize; 39 | Dicc->rules = (Trule*) malloc (Dicc->maxsize * sizeof(Trule)); 40 | } 41 | else 42 | { Dicc->maxsize /= Dicc->factor; 43 | Dicc->rules = (Trule*) realloc (Dicc->rules, Dicc->maxsize * sizeof(Trule)); 44 | } 45 | } 46 | id = Dicc->size++; 47 | nrule = &Dicc->rules[id]; 48 | *nrule = rule; 49 | 50 | return id; 51 | } 52 | 53 | 54 | Tdiccarray 55 | Dictionary::createDicc (float factor, int minsize) 56 | { Tdiccarray Dicc; 57 | Dicc.rules = NULL; 58 | Dicc.maxsize = 0; 59 | Dicc.size = 0; 60 | Dicc.factor = factor; 61 | Dicc.minsize = minsize; 62 | return Dicc; 63 | } 64 | 65 | void 66 | Dictionary::destroyDicc (Tdiccarray *Dicc) 67 | { if (Dicc->maxsize == 0) return; 68 | free (Dicc->rules); 69 | Dicc->rules = NULL; 70 | Dicc->maxsize = 0; 71 | Dicc->size = 0; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /RePair/Coder/dictionary.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Repair -- an implementation of Larsson and Moffat's compression and 5 | decompression algorithms. 6 | Copyright (C) 2010-current_year Gonzalo Navarro 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | 22 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 23 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 24 | 25 | */ 26 | 27 | // extendible array for records 28 | 29 | #ifndef DICTIONARYINCLUDED 30 | #define DICTIONARYINCLUDED 31 | 32 | #include 33 | #include "basics.h" 34 | 35 | typedef struct 36 | { Tpair rule; // left and righ component 37 | int l; // rule length 38 | } Trule; 39 | 40 | typedef struct 41 | { Trule *rules; 42 | int maxsize; 43 | int size; 44 | float factor; 45 | int minsize; 46 | } Tdiccarray; 47 | 48 | // contents can be accessed as Dic.rules[0..Dicc.size-1] 49 | class Dictionary 50 | { 51 | public: 52 | // inserts rule in Dicc, returns id 53 | static int insertRule (Tdiccarray *Dicc, Trule rule); 54 | // creates empty dictionary 55 | static Tdiccarray createDicc (float factor, int minsize); 56 | // destroys Rec 57 | static void destroyDicc (Tdiccarray *Dicc); 58 | }; 59 | #endif 60 | -------------------------------------------------------------------------------- /RePair/Coder/hash.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Repair -- an implementation of Larsson and Moffat's compression and 5 | decompression algorithms. 6 | Copyright (C) 2010-current_year Gonzalo Navarro 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | 22 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 23 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 24 | 25 | */ 26 | 27 | // linear probing hash table for pairs 28 | 29 | #ifndef HASHINCLUDED 30 | #define HASHINCLUDED 31 | 32 | #include "basics.h" 33 | #include "records.h" 34 | 35 | // 1/extra space overhead; set closer to 1 for smaller and slower execution 36 | static const float factor = 0.75; 37 | 38 | typedef unsigned long long relong; 39 | #define LPRIME ((relong)767865341467865341) 40 | #define PRIME 2013686449 41 | 42 | typedef struct 43 | { int *table; 44 | int maxpos; // of the form (1<Rec[id].pair in hash 57 | // assumes it is not already there 58 | // sets ptr from Rec to hash as well 59 | static void insertHash (Thash *H, int id); 60 | // deletes H->Rec[id].pair from hash 61 | static void deleteHash (Thash *H, int id); 62 | // returns id, -1 if not existing 63 | static int searchHash (Thash H, Tpair p); 64 | // repositions pair 65 | static void hashRepos (Thash *H, int id); 66 | 67 | static int finsertHash (Thash H, Tpair p) ; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /RePair/Coder/records.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Repair -- an implementation of Larsson and Moffat's compression and 5 | decompression algorithms. 6 | Copyright (C) 2010-current_year Gonzalo Navarro 7 | 8 | This program is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU General Public License 10 | as published by the Free Software Foundation; either version 2 11 | of the License, or (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | 22 | Author's contact: Gonzalo Navarro, Dept. of Computer Science, University of 23 | Chile. Blanco Encalada 2120, Santiago, Chile. gnavarro@dcc.uchile.cl 24 | 25 | */ 26 | 27 | // extendible array for records 28 | 29 | #ifndef RECORDSINCLUDED 30 | #define RECORDSINCLUDED 31 | 32 | #include "stdio.h" 33 | #include "basics.h" 34 | 35 | typedef struct 36 | { int prev,next; 37 | } Tlist; // list of prev next equal char 38 | 39 | typedef struct 40 | { Tpair pair; // pair content 41 | int freq; // frequency 42 | int cpos; // 1st position in C 43 | int hpos; // position in heap 44 | int kpos; // position in hash 45 | } Trecord; 46 | 47 | typedef struct 48 | { Trecord *records; 49 | int maxsize; 50 | int size; 51 | float factor; 52 | int minsize; 53 | void *Hash; // Thash * 54 | void *Heap; // Theap * 55 | void *List; // Tlist * 56 | } Trarray; 57 | 58 | #include "heap.h" 59 | #include "hash.h" 60 | 61 | // contents can be accessed as Rec.records[0..Rec.size-1] 62 | class Records 63 | { 64 | public: 65 | // inserts pair in Rec, returns id, links to/from 66 | // Hash and Heap, not List. sets freq = 1 67 | static int insertRecord (Trarray *Rec, Tpair pair); 68 | // deletes last cell in Rec 69 | static void deleteRecord (Trarray *Rec); 70 | // creates empty array 71 | static Trarray createRecords (float factor, int minsize); 72 | // associates structures 73 | static void assocRecords (Trarray *Rec, void *Hash, void *Heap, void *List); 74 | // destroys Rec 75 | static void destroyRecords (Trarray *Rec); 76 | // delete record, freq <= 1 77 | // due to freq 0 or purgue (freq 1) 78 | // already deleted from heap 79 | static void removeRecord (Trarray *Rec, int id); 80 | }; 81 | #endif 82 | -------------------------------------------------------------------------------- /StringDictionary.cpp: -------------------------------------------------------------------------------- 1 | /* StringDictionary.cpp 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * Abstract class for implementing Compressed String Dictionaries. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 | * Contacting the authors: 23 | * Francisco Claude: fclaude@recoded.cl 24 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 25 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 26 | */ 27 | 28 | #include "StringDictionary.h" 29 | 30 | StringDictionary* 31 | StringDictionary::load(ifstream & fp, uint opt) 32 | { 33 | size_t r = loadValue(fp); 34 | fp.seekg(0, fp.beg); 35 | 36 | switch(r) 37 | { 38 | case HASHHF: return StringDictionaryHASHHF::load(fp, opt); 39 | case HASHUFFDAC: return StringDictionaryHASHUFFDAC::load(fp); 40 | case HASHRPF: return StringDictionaryHASHRPF::load(fp, opt); 41 | case HASHRPDAC: return StringDictionaryHASHRPDAC::load(fp); 42 | 43 | case PFC: return StringDictionaryPFC::load(fp); 44 | case RPFC: return StringDictionaryRPFC::load(fp); 45 | 46 | case HTFC: return StringDictionaryHTFC::load(fp); 47 | case HHTFC: return StringDictionaryHHTFC::load(fp); 48 | case RPHTFC: return StringDictionaryRPHTFC::load(fp); 49 | 50 | case RPDAC: return StringDictionaryRPDAC::load(fp); 51 | case FMINDEX: return StringDictionaryFMINDEX::load(fp); 52 | case DXBW: return StringDictionaryXBW::load(fp); 53 | } 54 | 55 | return NULL; 56 | } 57 | 58 | uint 59 | StringDictionary::maxLength() 60 | { 61 | return maxlength; 62 | } 63 | 64 | size_t 65 | StringDictionary::numElements() 66 | { 67 | return elements; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /XBW/TrieNode.h: -------------------------------------------------------------------------------- 1 | /* TrieNode.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * TrieNode for the XBW 6 | 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * 23 | * Contacting the authors: 24 | * Francisco Claude: fclaude@recoded.cl 25 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 26 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 27 | */ 28 | 29 | #ifndef TRIENODE_H_ 30 | #define TRIENODE_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | using namespace std; 37 | 38 | #include 39 | using namespace cds_utils; 40 | 41 | class TrieNode { 42 | 43 | public: 44 | TrieNode(char symbol); 45 | 46 | void insert(const uchar *str, int len, int *occ, vector *nodes); 47 | bool less(const TrieNode & n) const; 48 | bool cmp(const TrieNode & n) const; 49 | 50 | virtual ~TrieNode(); 51 | 52 | protected: 53 | uchar symbol; 54 | map children; 55 | TrieNode *parent; 56 | uchar last_ch; 57 | bool leaf; 58 | bool last; 59 | 60 | friend class StringDictionaryXBW; 61 | }; 62 | 63 | #endif /* TRIENODE_H_ */ 64 | -------------------------------------------------------------------------------- /iterators/IteratorDictID.h: -------------------------------------------------------------------------------- 1 | /* IteratorDictID.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * Iterator class for scanning streams of IDs. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 | * Contacting the authors: 23 | * Francisco Claude: fclaude@recoded.cl 24 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 25 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 26 | */ 27 | 28 | #ifndef _ITERATORDICTID_H 29 | #define _ITERATORDICTID_H 30 | 31 | 32 | #include 33 | using namespace std; 34 | 35 | class IteratorDictID 36 | { 37 | public: 38 | /** Checks for non-processed IDs in the stream. 39 | @returns if remains non-processed IDs. 40 | */ 41 | bool hasNext() { return processed 33 | using namespace std; 34 | 35 | class IteratorDictIDContiguous : public IteratorDictID 36 | { 37 | public: 38 | /** ID Iterator Constructor for streams of contiguous elements. 39 | @param left: the first element ID (left limit) 40 | @param right: the last element ID (right limit) 41 | */ 42 | IteratorDictIDContiguous(size_t left, size_t right) 43 | { 44 | this->leftLimit = left; 45 | this->rightLimit = right; 46 | this->scanneable = right; 47 | 48 | this->processed = left-1; 49 | } 50 | 51 | /** Extracts the next ID in the stream. 52 | @returns the next ID. 53 | */ 54 | size_t next() { return ++processed; } 55 | 56 | /** Obtains the left limit of the stream. That is, the ID of 57 | the first element in the stream. 58 | @returns the left limit. 59 | */ 60 | size_t getLeftLimit() { return leftLimit; } 61 | 62 | /** Obtains the right limit of the stream. That is, the ID of 63 | the last element in the stream. 64 | @returns the right limit. 65 | */ 66 | size_t getRightLimit() { return rightLimit; } 67 | 68 | /** Generic destructor */ 69 | ~IteratorDictIDContiguous() {} 70 | 71 | protected: 72 | size_t leftLimit; // Left stream limit 73 | size_t rightLimit; // Right stream limit 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /iterators/IteratorDictIDDuplicates.h: -------------------------------------------------------------------------------- 1 | /* IteratorDictIDDuplicates.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * Iterator class for scanning streams of IDs containing duplicates. 6 | * The IDs must be sorted before scanning!!! 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * 23 | * Contacting the authors: 24 | * Francisco Claude: fclaude@recoded.cl 25 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 26 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 27 | */ 28 | 29 | #ifndef _ITERATORDICTIDDUPLICATES_H 30 | #define _ITERATORDICTIDDUPLICATES_H 31 | 32 | 33 | #include 34 | using namespace std; 35 | 36 | class IteratorDictIDDuplicates : public IteratorDictID 37 | { 38 | public: 39 | /** ID Iterator Constructor for streams of duplicated elements. 40 | @param ids: the array of ids 41 | @param scanneable: the number of ids in the array 42 | */ 43 | IteratorDictIDDuplicates(size_t *ids, size_t scanneable) 44 | { 45 | this->ids = ids; 46 | this->scanneable = scanneable; 47 | 48 | this->processed = 0; 49 | } 50 | 51 | size_t next() 52 | { 53 | size_t next = ids[processed]; 54 | 55 | // Jumping duplicates results 56 | do { processed++; } while (ids[processed-1] == ids[processed]); 57 | 58 | return next; 59 | } 60 | 61 | 62 | /** Generic destructor */ 63 | ~IteratorDictIDDuplicates() { delete [] ids; } 64 | 65 | protected: 66 | size_t *ids; // Array of ids 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /iterators/IteratorDictIDNoContiguous.h: -------------------------------------------------------------------------------- 1 | /* IteratorDictIDNoContiguous.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * Iterator class for scanning streams of no contiguous IDs. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 | * Contacting the authors: 23 | * Francisco Claude: fclaude@recoded.cl 24 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 25 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 26 | */ 27 | 28 | #ifndef _ITERATORDICTIDNOCONTIGUOUS_H 29 | #define _ITERATORDICTIDNOCONTIGUOUS_H 30 | 31 | 32 | #include 33 | using namespace std; 34 | 35 | class IteratorDictIDNoContiguous : public IteratorDictID 36 | { 37 | public: 38 | /** ID Iterator Constructor for streams of contiguous elements. 39 | @param ids: the array of ids 40 | @param scanneable: the number of ids in the array 41 | */ 42 | IteratorDictIDNoContiguous(size_t *ids, size_t scanneable) 43 | { 44 | this->ids = ids; 45 | this->scanneable = scanneable; 46 | 47 | this->processed = 0; 48 | } 49 | 50 | /** Extracts the next ID in the stream. 51 | @returns the next ID. 52 | */ 53 | size_t next() { return ids[processed++]; } 54 | 55 | /** Generic destructor */ 56 | ~IteratorDictIDNoContiguous() { delete [] ids; } 57 | 58 | protected: 59 | size_t *ids; // Array of ids 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libcds/Changelog: -------------------------------------------------------------------------------- 1 | 2 | Version 0.9: 3 | 4 | - static_bitsequence: 5 | - added sdarray 6 | - static_sequence: 7 | - added sequence representation based in sdarray (no efficient access) 8 | 9 | Version 0.8: 10 | 11 | - trying: 12 | - git 13 | - missing: 14 | - improve design and class names 15 | - add namespaces 16 | - reference counters for coders and util clases 17 | - static_bitsequence: 18 | - Added base class with virtual functions 19 | - Added testing naive rank/select 20 | - Added rank/select with one-level sampling 21 | - Added compressed representation 22 | - static_sequence 23 | - Added wavelet tree without pointers 24 | - Added wavelet tree with pointers 25 | - Added coder for giving huffman/normal shape to the wavelet tree 26 | - Added Golynski et al.'s data structure for large alphabets 27 | - static_permutation 28 | - Added Diego Arroyuelo's implementation of Munro et al.'s permutations 29 | - Added base classes 30 | - TODO: check interface and add functionality 31 | - coders 32 | - temporal coders for the wavelet tree 33 | - TODO: add coders and a general interface for them 34 | - utils 35 | - Added the alphabet mapper interface 36 | - Added a dummy alphabet mapper 37 | 38 | 39 | -------------------------------------------------------------------------------- /libcds/Makefile: -------------------------------------------------------------------------------- 1 | 2 | #CPPFLAGS=-g3 -Wall -m32 -O0 3 | CPPFLAGS=-O9 -Wall -DNDEBUG 4 | 5 | all: clean libcompact 6 | 7 | doc: 8 | @echo " [DOC] Generating documentation" 9 | @doxygen 10 | 11 | libcompact: 12 | @echo " [MSG] Entering directory src" 13 | @CPPFLAGS="$(CPPFLAGS)" make --no-print-directory -C src 14 | 15 | tests: libcompact 16 | @echo " [MSG] Entering directory tests" 17 | @CPPFLAGS="$(CPPFLAGS)" make --no-print-directory -C tests 18 | 19 | clean: 20 | @echo " [MSG] Entering directory src" 21 | @make --no-print-directory -C src clean 22 | @echo " [MSG] Entering directory tests" 23 | @make --no-print-directory -C tests clean 24 | @echo " [CLN] Cleaning docs folder" 25 | @rm -rf docs/* 26 | @touch docs/delete_me 27 | @echo " [CLN] Cleaning lib folder" 28 | @rm -f lib/* 29 | @touch lib/delete_me 30 | @echo " [CLN] Cleaning includes folder" 31 | @rm -f includes/* 32 | @touch includes/delete_me 33 | 34 | 35 | -------------------------------------------------------------------------------- /libcds/docs/delete_me: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/docs/delete_me -------------------------------------------------------------------------------- /libcds/includes/delete_me: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/includes/delete_me -------------------------------------------------------------------------------- /libcds/lib/delete_me: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/lib/delete_me -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilder.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilder.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDER_H 23 | #define BITSEQUENCEBUILDER_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace cds_utils; 30 | 31 | namespace cds_static 32 | { 33 | /** Base class for BitSequence builders, it defines the build function 34 | * that takes only a bitmap. The parameters for construction are can 35 | * be set in any way by the builder, but none are received when 36 | * the actual building takes place. 37 | * 38 | * @author Francisco Claude 39 | */ 40 | class BitSequenceBuilder 41 | { 42 | public: 43 | BitSequenceBuilder() { userCount=0; } 44 | ~BitSequenceBuilder() {} 45 | virtual void use() { userCount++; } 46 | virtual void unuse() { userCount--; assert(userCount>=0); if(userCount==0) delete this; } 47 | virtual BitSequence * build(uint * bitseq, size_t len) const = 0; 48 | virtual BitSequence * build(const BitString & bs) const = 0; 49 | 50 | protected: 51 | int userCount; 52 | }; 53 | }; 54 | 55 | #include 56 | #include 57 | #include 58 | #include 59 | #endif 60 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderDArray.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderDArray.cpp 2 | * Copyright (C) 2010, Rodrigo Canovas, all rights reserved. 3 | * 4 | * Rodrigo Canovas 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderDArray::BitSequenceBuilderDArray() { 28 | } 29 | 30 | BitSequenceBuilderDArray::~BitSequenceBuilderDArray() { 31 | } 32 | 33 | BitSequence * BitSequenceBuilderDArray::build(uint * bitseq, size_t len) const 34 | { 35 | return new BitSequenceDArray(bitseq,len); 36 | } 37 | 38 | BitSequence * BitSequenceBuilderDArray::build(const BitString & bs) const 39 | { 40 | return new BitSequenceDArray(bs); 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderDArray.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderDArray.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Rodrigo Canovas 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERDARRAY_H 23 | #define BITSEQUENCEBUILDERDARRAY_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace cds_static 30 | { 31 | /** Base class for BitSequence builders, it defines the build function 32 | * that takes only a bitmap. The parameters for construction are can 33 | * be set in any way by the builder, but none are received when 34 | * the actual building takes place. 35 | * 36 | * @author Rodrigo Canovas 37 | */ 38 | class BitSequenceBuilderDArray : public BitSequenceBuilder 39 | { 40 | public: 41 | BitSequenceBuilderDArray(); 42 | virtual ~BitSequenceBuilderDArray(); 43 | virtual BitSequence * build(uint * bitseq, size_t len) const; 44 | virtual BitSequence * build(const BitString & bs) const; 45 | }; 46 | }; 47 | #endif 48 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderRG.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRG.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderRG::BitSequenceBuilderRG(uint factor) { 28 | this->factor = factor; 29 | } 30 | 31 | BitSequence * BitSequenceBuilderRG::build(uint * bitseq, size_t len) const 32 | { 33 | return new BitSequenceRG(bitseq,len,factor); 34 | } 35 | 36 | BitSequence * BitSequenceBuilderRG::build(const BitString & bs) const 37 | { 38 | return new BitSequenceRG(bs,factor); 39 | } 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderRG.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRG.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERRG_H 23 | #define BITSEQUENCEBUILDERRG_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace cds_static 30 | { 31 | /** BitSequence builder for BitSequenceRG 32 | * 33 | * @author Francisco Claude 34 | */ 35 | class BitSequenceBuilderRG : public BitSequenceBuilder 36 | { 37 | public: 38 | BitSequenceBuilderRG(uint factor); 39 | virtual ~BitSequenceBuilderRG() {} 40 | virtual BitSequence * build(uint * bitseq, size_t len) const; 41 | virtual BitSequence * build(const BitString & bs) const; 42 | protected: 43 | uint factor; 44 | }; 45 | }; 46 | #endif 47 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderRRR.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRRR.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderRRR::BitSequenceBuilderRRR(uint sample_rate) { 28 | this->sample_rate = sample_rate; 29 | } 30 | 31 | BitSequence * BitSequenceBuilderRRR::build(uint * bitseq, size_t len) const 32 | { 33 | return new BitSequenceRRR(bitseq,len,sample_rate); 34 | } 35 | 36 | BitSequence * BitSequenceBuilderRRR::build(const BitString & bs) const 37 | { 38 | return new BitSequenceRRR(bs,sample_rate); 39 | } 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderRRR.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRRR.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERRRR_H 23 | #define BITSEQUENCEBUILDERRRR_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace cds_utils; 30 | 31 | namespace cds_static 32 | { 33 | /** BitSequence builder for RRR BitSequences. 34 | * 35 | * @author Francisco Claude 36 | */ 37 | class BitSequenceBuilderRRR : public BitSequenceBuilder 38 | { 39 | public: 40 | BitSequenceBuilderRRR(uint sample_rate); 41 | virtual ~BitSequenceBuilderRRR() {} 42 | virtual BitSequence * build(uint * bitseq, size_t len) const; 43 | virtual BitSequence * build(const BitString & bs) const; 44 | protected: 45 | uint sample_rate; 46 | }; 47 | }; 48 | #endif 49 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderSDArray.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderSDArray.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderSDArray::BitSequenceBuilderSDArray() { 28 | } 29 | 30 | BitSequenceBuilderSDArray::~BitSequenceBuilderSDArray() { 31 | } 32 | 33 | BitSequence * BitSequenceBuilderSDArray::build(uint * bitseq, size_t len) const 34 | { 35 | return new BitSequenceSDArray(bitseq,len); 36 | } 37 | 38 | BitSequence * BitSequenceBuilderSDArray::build(const BitString & bs) const 39 | { 40 | return new BitSequenceSDArray(bs); 41 | } 42 | 43 | }; 44 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceBuilderSDArray.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderSDArray.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERSDARRAY_H 23 | #define BITSEQUENCEBUILDERSDARRAY_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace cds_static 30 | { 31 | /** Base class for BitSequence builders, it defines the build function 32 | * that takes only a bitmap. The parameters for construction are can 33 | * be set in any way by the builder, but none are received when 34 | * the actual building takes place. 35 | * 36 | * @author Francisco Claude 37 | */ 38 | class BitSequenceBuilderSDArray : public BitSequenceBuilder 39 | { 40 | public: 41 | BitSequenceBuilderSDArray(); 42 | virtual ~BitSequenceBuilderSDArray(); 43 | virtual BitSequence * build(uint * bitseq, size_t len) const; 44 | virtual BitSequence * build(const BitString & bs) const; 45 | }; 46 | }; 47 | #endif 48 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/BitSequenceSDArray.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceSDArray.h 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This class is a wrapper for the file sdarraySadakane, 7 | * implemented by K. Sadakane. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef _BITSEQUENCESDARRAY_H 26 | #define _BITSEQUENCESDARRAY_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | using namespace cds_utils; 35 | 36 | namespace cds_static 37 | { 38 | class BitSequenceSDArray: public BitSequence 39 | { 40 | 41 | public: 42 | /** Builds the SDArray */ 43 | BitSequenceSDArray(const BitString & bs); 44 | /** Builds the SDArray */ 45 | BitSequenceSDArray(uint * buff, size_t len); 46 | virtual ~BitSequenceSDArray(); 47 | virtual size_t select1(size_t i) const; 48 | virtual size_t rank1(size_t i) const; 49 | virtual size_t selectNext1(size_t i) const; 50 | virtual size_t getSize() const; 51 | virtual void save(ofstream & fp) const; 52 | static BitSequenceSDArray * load(ifstream & fp); 53 | 54 | protected: 55 | selects3 sd; 56 | BitSequenceSDArray(); 57 | 58 | }; 59 | }; 60 | #endif 61 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp -f *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence (copia)/sdarraySadakane.h: -------------------------------------------------------------------------------- 1 | /* sdarraySadakane.h 2 | * Copyright (C) 2009, K. Sadakane, all rights reserved. 3 | * 4 | * This is an adapatation of the original sdarray implementation 5 | * by K. Sadakane. Modifications and probable bugs were introduced 6 | * by Francisco Claude. 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef SDARRAY_H 25 | #define SDARRAY_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace cds_static 37 | { 38 | 39 | using namespace cds_utils; 40 | 41 | typedef struct 42 | { 43 | int n,m; 44 | int size; 45 | unsigned char *buf; 46 | uint *lp; 47 | uint *sl; 48 | ushort *ss; 49 | uint ss_len, sl_len; 50 | uint *p; 51 | } selectd2; 52 | 53 | typedef struct 54 | { 55 | int n,m,d; 56 | int size; 57 | unsigned char *hi; 58 | uint *low; 59 | selectd2 *sd0,*sd1; 60 | uint hi_len, low_len; 61 | //uint lasti, lasts; 62 | } selects3; 63 | 64 | int selects3_construct(selects3 *select, const int n, const uint *buf); 65 | int selects3_select(const selects3 *select, const int i); 66 | int selects3_rank(const selects3 *select, const int i); 67 | int selects3_selectnext(const selects3 *select, const int i); 68 | 69 | void make___selecttbl(void); 70 | void selectd2_save(const selectd2 * s, ofstream & fp); 71 | void selects3_save(const selects3 * s, ofstream & fp); 72 | 73 | void selectd2_load(selectd2 * s, ifstream & fp); 74 | void selects3_load(selects3 * s, ifstream & fp); 75 | 76 | void selectd2_free(selectd2 * s); 77 | void selects3_free(selects3 * s); 78 | 79 | } 80 | #endif 81 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilder.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilder.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDER_H 23 | #define BITSEQUENCEBUILDER_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace cds_utils; 30 | 31 | namespace cds_static 32 | { 33 | /** Base class for BitSequence builders, it defines the build function 34 | * that takes only a bitmap. The parameters for construction are can 35 | * be set in any way by the builder, but none are received when 36 | * the actual building takes place. 37 | * 38 | * @author Francisco Claude 39 | */ 40 | class BitSequenceBuilder 41 | { 42 | public: 43 | BitSequenceBuilder() { userCount=0; } 44 | ~BitSequenceBuilder() {} 45 | virtual void use() { userCount++; } 46 | virtual void unuse() { userCount--; assert(userCount>=0); if(userCount==0) delete this; } 47 | virtual BitSequence * build(uint * bitseq, size_t len) const = 0; 48 | virtual BitSequence * build(const BitString & bs) const = 0; 49 | 50 | protected: 51 | int userCount; 52 | }; 53 | }; 54 | 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #endif 61 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilder375.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilder375.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | BitSequence * BitSequenceBuilder375::build(uint * bitseq, size_t len) const 27 | { 28 | return new BitSequence375(bitseq, len); 29 | } 30 | 31 | BitSequence * BitSequenceBuilder375::build(const BitString & bs) const 32 | { 33 | return new BitSequence375(bs.getData(), bs.getLength()); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilder375.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilder375.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDER375_H 23 | #define BITSEQUENCEBUILDER375_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace cds_static 30 | { 31 | /** BitSequence builder for BitSequence375 32 | * 33 | * @author Francisco Claude 34 | */ 35 | class BitSequenceBuilder375 : public BitSequenceBuilder 36 | { 37 | public: 38 | BitSequenceBuilder375() {}; 39 | virtual ~BitSequenceBuilder375() {}; 40 | virtual BitSequence * build(uint * bitseq, size_t len) const; 41 | virtual BitSequence * build(const BitString & bs) const; 42 | }; 43 | }; 44 | #endif 45 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderDArray.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderDArray.cpp 2 | * Copyright (C) 2010, Rodrigo Canovas, all rights reserved. 3 | * 4 | * Rodrigo Canovas 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderDArray::BitSequenceBuilderDArray() { 28 | } 29 | 30 | BitSequenceBuilderDArray::~BitSequenceBuilderDArray() { 31 | } 32 | 33 | BitSequence * BitSequenceBuilderDArray::build(uint * bitseq, size_t len) const 34 | { 35 | return new BitSequenceDArray(bitseq,len); 36 | } 37 | 38 | BitSequence * BitSequenceBuilderDArray::build(const BitString & bs) const 39 | { 40 | return new BitSequenceDArray(bs); 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderDArray.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderDArray.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Rodrigo Canovas 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERDARRAY_H 23 | #define BITSEQUENCEBUILDERDARRAY_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace cds_static 30 | { 31 | /** Base class for BitSequence builders, it defines the build function 32 | * that takes only a bitmap. The parameters for construction are can 33 | * be set in any way by the builder, but none are received when 34 | * the actual building takes place. 35 | * 36 | * @author Rodrigo Canovas 37 | */ 38 | class BitSequenceBuilderDArray : public BitSequenceBuilder 39 | { 40 | public: 41 | BitSequenceBuilderDArray(); 42 | virtual ~BitSequenceBuilderDArray(); 43 | virtual BitSequence * build(uint * bitseq, size_t len) const; 44 | virtual BitSequence * build(const BitString & bs) const; 45 | }; 46 | }; 47 | #endif 48 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderRG.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRG.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderRG::BitSequenceBuilderRG(uint factor) { 28 | this->factor = factor; 29 | } 30 | 31 | BitSequence * BitSequenceBuilderRG::build(uint * bitseq, size_t len) const 32 | { 33 | return new BitSequenceRG(bitseq,len,factor); 34 | } 35 | 36 | BitSequence * BitSequenceBuilderRG::build(const BitString & bs) const 37 | { 38 | return new BitSequenceRG(bs,factor); 39 | } 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderRG.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRG.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERRG_H 23 | #define BITSEQUENCEBUILDERRG_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace cds_static 30 | { 31 | /** BitSequence builder for BitSequenceRG 32 | * 33 | * @author Francisco Claude 34 | */ 35 | class BitSequenceBuilderRG : public BitSequenceBuilder 36 | { 37 | public: 38 | BitSequenceBuilderRG(uint factor); 39 | virtual ~BitSequenceBuilderRG() {} 40 | virtual BitSequence * build(uint * bitseq, size_t len) const; 41 | virtual BitSequence * build(const BitString & bs) const; 42 | protected: 43 | uint factor; 44 | }; 45 | }; 46 | #endif 47 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderRRR.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRRR.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderRRR::BitSequenceBuilderRRR(uint sample_rate) { 28 | this->sample_rate = sample_rate; 29 | } 30 | 31 | BitSequence * BitSequenceBuilderRRR::build(uint * bitseq, size_t len) const 32 | { 33 | return new BitSequenceRRR(bitseq,len,sample_rate); 34 | } 35 | 36 | BitSequence * BitSequenceBuilderRRR::build(const BitString & bs) const 37 | { 38 | return new BitSequenceRRR(bs,sample_rate); 39 | } 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderRRR.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderRRR.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERRRR_H 23 | #define BITSEQUENCEBUILDERRRR_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace cds_utils; 30 | 31 | namespace cds_static 32 | { 33 | /** BitSequence builder for RRR BitSequences. 34 | * 35 | * @author Francisco Claude 36 | */ 37 | class BitSequenceBuilderRRR : public BitSequenceBuilder 38 | { 39 | public: 40 | BitSequenceBuilderRRR(uint sample_rate); 41 | virtual ~BitSequenceBuilderRRR() {} 42 | virtual BitSequence * build(uint * bitseq, size_t len) const; 43 | virtual BitSequence * build(const BitString & bs) const; 44 | protected: 45 | uint sample_rate; 46 | }; 47 | }; 48 | #endif 49 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderSDArray.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderSDArray.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | BitSequenceBuilderSDArray::BitSequenceBuilderSDArray() { 28 | } 29 | 30 | BitSequenceBuilderSDArray::~BitSequenceBuilderSDArray() { 31 | } 32 | 33 | BitSequence * BitSequenceBuilderSDArray::build(uint * bitseq, size_t len) const 34 | { 35 | return new BitSequenceSDArray(bitseq,len); 36 | } 37 | 38 | BitSequence * BitSequenceBuilderSDArray::build(const BitString & bs) const 39 | { 40 | return new BitSequenceSDArray(bs); 41 | } 42 | 43 | }; 44 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceBuilderSDArray.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceBuilderSDArray.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef BITSEQUENCEBUILDERSDARRAY_H 23 | #define BITSEQUENCEBUILDERSDARRAY_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace cds_static 30 | { 31 | /** Base class for BitSequence builders, it defines the build function 32 | * that takes only a bitmap. The parameters for construction are can 33 | * be set in any way by the builder, but none are received when 34 | * the actual building takes place. 35 | * 36 | * @author Francisco Claude 37 | */ 38 | class BitSequenceBuilderSDArray : public BitSequenceBuilder 39 | { 40 | public: 41 | BitSequenceBuilderSDArray(); 42 | virtual ~BitSequenceBuilderSDArray(); 43 | virtual BitSequence * build(uint * bitseq, size_t len) const; 44 | virtual BitSequence * build(const BitString & bs) const; 45 | }; 46 | }; 47 | #endif 48 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/BitSequenceSDArray.h: -------------------------------------------------------------------------------- 1 | /* BitSequenceSDArray.h 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This class is a wrapper for the file sdarraySadakane, 7 | * implemented by K. Sadakane. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef _BITSEQUENCESDARRAY_H 26 | #define _BITSEQUENCESDARRAY_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | using namespace cds_utils; 35 | 36 | namespace cds_static 37 | { 38 | class BitSequenceSDArray: public BitSequence 39 | { 40 | 41 | public: 42 | /** Builds the SDArray */ 43 | BitSequenceSDArray(const BitString & bs); 44 | /** Builds the SDArray */ 45 | BitSequenceSDArray(uint * buff, size_t len); 46 | virtual ~BitSequenceSDArray(); 47 | virtual size_t select1(size_t i) const; 48 | virtual size_t rank1(size_t i) const; 49 | virtual size_t selectNext1(size_t i) const; 50 | virtual size_t getSize() const; 51 | virtual void save(ofstream & fp) const; 52 | static BitSequenceSDArray * load(ifstream & fp); 53 | 54 | protected: 55 | selects3 sd; 56 | BitSequenceSDArray(); 57 | 58 | }; 59 | }; 60 | #endif 61 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp -f *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/bitsequence/sdarraySadakane.h: -------------------------------------------------------------------------------- 1 | /* sdarraySadakane.h 2 | * Copyright (C) 2009, K. Sadakane, all rights reserved. 3 | * 4 | * This is an adapatation of the original sdarray implementation 5 | * by K. Sadakane. Modifications and probable bugs were introduced 6 | * by Francisco Claude. 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef SDARRAY_H 25 | #define SDARRAY_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace cds_static 37 | { 38 | 39 | using namespace cds_utils; 40 | 41 | typedef struct 42 | { 43 | int n,m; 44 | int size; 45 | unsigned char *buf; 46 | uint *lp; 47 | uint *sl; 48 | ushort *ss; 49 | uint ss_len, sl_len; 50 | uint *p; 51 | } selectd2; 52 | 53 | typedef struct 54 | { 55 | int n,m,d; 56 | int size; 57 | unsigned char *hi; 58 | uint *low; 59 | selectd2 *sd0,*sd1; 60 | uint hi_len, low_len; 61 | //uint lasti, lasts; 62 | } selects3; 63 | 64 | int selects3_construct(selects3 *select, const int n, const uint *buf); 65 | int selects3_select(const selects3 *select, const int i); 66 | int selects3_rank(const selects3 *select, const int i); 67 | int selects3_selectnext(const selects3 *select, const int i); 68 | 69 | void make___selecttbl(void); 70 | void selectd2_save(const selectd2 * s, ofstream & fp); 71 | void selects3_save(const selects3 * s, ofstream & fp); 72 | 73 | void selectd2_load(selectd2 * s, ifstream & fp); 74 | void selects3_load(selects3 * s, ifstream & fp); 75 | 76 | void selectd2_free(selectd2 * s); 77 | void selects3_free(selects3 * s); 78 | 79 | } 80 | #endif 81 | -------------------------------------------------------------------------------- /libcds/src/static/coders/Coder.h: -------------------------------------------------------------------------------- 1 | /* Coder.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef CODER_H 23 | #define CODER_H 24 | 25 | #include 26 | #include 27 | namespace cds_static 28 | { 29 | 30 | class Coder 31 | { 32 | public: 33 | virtual size_t encode(uint symb, uint * stream, size_t pos) const = 0; 34 | virtual size_t decode(uint * symb, uint *stream, size_t pos) const = 0; 35 | virtual size_t maxLength() const = 0; 36 | virtual size_t getSize() const = 0; 37 | virtual void save(ofstream & fp) const = 0; 38 | static Coder * load(ifstream & fp); 39 | }; 40 | 41 | }; 42 | 43 | #include 44 | #endif 45 | -------------------------------------------------------------------------------- /libcds/src/static/coders/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp -f *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/mapper/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp -f *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/mapper/Mapper.cpp: -------------------------------------------------------------------------------- 1 | /* mapper.cpp 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * static_bitsequence definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | Mapper::Mapper() { 27 | userCount=0; 28 | } 29 | 30 | void Mapper::use() { 31 | userCount++; 32 | } 33 | 34 | void Mapper::unuse() { 35 | userCount--; 36 | assert(userCount>=0); 37 | if(userCount==0) 38 | delete this; 39 | } 40 | 41 | Mapper * Mapper::load(ifstream & input) { 42 | uint rd; 43 | input.read((char*)&rd,sizeof(uint)); 44 | size_t pos = input.tellg(); 45 | input.seekg(pos-sizeof(uint)); 46 | switch(rd) { 47 | case MAPPER_NONE_HDR: return MapperNone::load(input); 48 | case MAPPER_CONT_HDR: return MapperCont::load(input); 49 | } 50 | return NULL; 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /libcds/src/static/mapper/Mapper.h: -------------------------------------------------------------------------------- 1 | /* Mapper.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Mapper definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef _MAPPER_H 23 | #define _MAPPER_H 24 | 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | namespace cds_static 31 | { 32 | 33 | #define MAPPER_NONE_HDR 2 34 | #define MAPPER_CONT_HDR 3 35 | 36 | /** Base class for alphabet mappers 37 | * 38 | * @author Francisco Claude 39 | */ 40 | class Mapper 41 | { 42 | public: 43 | Mapper(); 44 | virtual ~Mapper() {} 45 | /** Maps the symbol */ 46 | virtual uint map(uint s) const=0; 47 | /** Unmaps the symbol */ 48 | virtual uint unmap(uint s) const=0; 49 | /** Returns the size of the mapper */ 50 | virtual size_t getSize() const=0; 51 | /** Saves the mapper to a file */ 52 | virtual void save(ofstream & out) const=0; 53 | /** Loads the mapper from a file */ 54 | static Mapper * load(ifstream & input); 55 | /** Reference counter incrementor */ 56 | virtual void use(); 57 | /** Reference counter decrementor */ 58 | virtual void unuse(); 59 | 60 | protected: 61 | /** Nr of references */ 62 | int userCount; 63 | }; 64 | }; 65 | 66 | #include 67 | #include 68 | #endif /* _MAPPER_H */ 69 | -------------------------------------------------------------------------------- /libcds/src/static/mapper/MapperCont.h: -------------------------------------------------------------------------------- 1 | /* mapper_cont.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * mapper_cont definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef _MAPPERCONT_H 23 | #define _MAPPERCONT_H 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | using namespace cds_utils; 35 | 36 | namespace cds_static 37 | { 38 | 39 | /** Mapper that makes the values in the set contiguous 40 | * 41 | * @author Francisco Claude 42 | */ 43 | class MapperCont : public Mapper 44 | { 45 | public: 46 | MapperCont(const Array & seq, const BitSequenceBuilder & bsb); 47 | MapperCont(const uint * A, const size_t len, const BitSequenceBuilder & bsb); 48 | 49 | virtual ~MapperCont(); 50 | 51 | virtual uint map(uint s) const; 52 | virtual uint unmap(uint s) const; 53 | virtual size_t getSize() const; 54 | 55 | virtual void save(ofstream & out) const; 56 | static MapperCont * load(ifstream & input); 57 | 58 | protected: 59 | MapperCont(); 60 | BitSequence * m; 61 | }; 62 | 63 | }; 64 | #endif /* _MAPPERCONT_H */ 65 | -------------------------------------------------------------------------------- /libcds/src/static/mapper/MapperNone.cpp: -------------------------------------------------------------------------------- 1 | /* MapperNone.cpp 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * mapper definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | MapperNone::MapperNone() { } 27 | 28 | uint MapperNone::map(const uint s) const {return s;} 29 | 30 | uint MapperNone::unmap(const uint s) const {return s;} 31 | 32 | size_t MapperNone::getSize() const { return sizeof(MapperNone); } 33 | 34 | void MapperNone::save(ofstream & out) const 35 | { 36 | uint wr = MAPPER_NONE_HDR; 37 | out.write((char*)&wr,sizeof(uint)); 38 | } 39 | 40 | MapperNone * MapperNone::load(ifstream & input) { 41 | uint rd; 42 | input.read((char*)&rd,sizeof(uint)); 43 | if(rd!=MAPPER_NONE_HDR) return NULL; 44 | return new MapperNone(); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /libcds/src/static/mapper/MapperNone.h: -------------------------------------------------------------------------------- 1 | /* MapperNone.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * MapperNone definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef _MAPPERNONE_H 23 | #define _MAPPERNONE_H 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | 32 | namespace cds_static 33 | { 34 | 35 | /** Mapper that doesn't change the value (identity) 36 | * 37 | * @author Francisco Claude 38 | */ 39 | class MapperNone : public Mapper 40 | { 41 | public: 42 | MapperNone(); 43 | virtual ~MapperNone() {} 44 | virtual uint map(const uint s) const; 45 | virtual uint unmap(const uint s) const; 46 | virtual size_t getSize() const; 47 | virtual void save(ofstream & out) const; 48 | static MapperNone * load(ifstream & input); 49 | }; 50 | }; 51 | #endif /* __MAPPER_NONE_H */ 52 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/Permutation.cpp: -------------------------------------------------------------------------------- 1 | /* Permutation.cpp 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | 22 | #include 23 | 24 | namespace cds_static { 25 | 26 | Permutation::Permutation() { length = 0; } 27 | 28 | Permutation::~Permutation() {} 29 | 30 | uint Permutation::pi(uint i) const { 31 | return pi(i,1); 32 | } 33 | 34 | uint Permutation::revpi(uint i) const { 35 | return revpi(i,1); 36 | } 37 | 38 | uint Permutation::pi(uint i, uint k) const { 39 | uint ret = i; 40 | while(k-->0) 41 | ret = pi(ret); 42 | return ret; 43 | } 44 | 45 | uint Permutation::revpi(uint i, uint k) const { 46 | uint ret = i; 47 | while(k-->0) 48 | ret = revpi(ret); 49 | return ret; 50 | } 51 | 52 | size_t Permutation::getLength() const { 53 | return length; 54 | } 55 | 56 | void Permutation::save(ofstream & fp) const { 57 | saveValue(fp,length); 58 | } 59 | 60 | Permutation * Permutation::load(ifstream & fp) { 61 | uint rd = loadValue(fp); 62 | size_t pos = fp.tellg(); 63 | fp.seekg(pos - sizeof(uint),ios::beg); 64 | switch(rd) { 65 | case MRRRPERM: return PermutationMRRR::load(fp); 66 | break; 67 | } 68 | return NULL; 69 | } 70 | 71 | 72 | }; 73 | 74 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/Permutation.h: -------------------------------------------------------------------------------- 1 | /* Permutation.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #ifndef __PERMUTATION_H 24 | #define __PERMUTATION_H 25 | 26 | using namespace cds_utils; 27 | 28 | namespace cds_static { 29 | class Permutation { 30 | public: 31 | Permutation(); 32 | virtual ~Permutation(); 33 | 34 | /** Compute the value at position i 35 | */ 36 | virtual uint pi(uint i) const; 37 | 38 | /** Compute the position where i appears */ 39 | virtual uint revpi(uint i) const; 40 | 41 | /** Compose pi k times. 42 | */ 43 | virtual uint pi(uint i, uint k) const; 44 | 45 | /** Compose revpi k times 46 | */ 47 | virtual uint revpi(uint i, uint k) const; 48 | 49 | /** retrieves the length of the permutation 50 | */ 51 | virtual size_t getLength() const; 52 | 53 | /** Size in bytes 54 | */ 55 | virtual size_t getSize() const = 0; 56 | 57 | /** Saves permutation to stream */ 58 | virtual void save(ofstream & fp) const; 59 | 60 | /** Loads the permutation */ 61 | static Permutation * load(ifstream & fp); 62 | 63 | protected: 64 | size_t length; 65 | }; 66 | }; 67 | 68 | #define MRRRPERM 1 69 | 70 | #include 71 | 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/PermutationBuilder.h: -------------------------------------------------------------------------------- 1 | /* PermutationBuilder.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef PERMUTATIONBUILDER_H 22 | #define PERMUTATIONBUILDER_H 23 | 24 | #include 25 | #include 26 | 27 | namespace cds_static { 28 | 29 | class PermutationBuilder { 30 | public: 31 | PermutationBuilder() { userCount=0; } 32 | virtual ~PermutationBuilder() {} 33 | virtual Permutation * build(uint * perm, uint n) const = 0; 34 | virtual void use() { userCount++; } 35 | virtual void unuse() { userCount--; assert(userCount>=0); if(userCount==0) delete this; } 36 | 37 | protected: 38 | int userCount; 39 | }; 40 | }; 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/PermutationBuilderMRRR.cpp: -------------------------------------------------------------------------------- 1 | /* PermutationBuilderMRRR.cpp 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | namespace cds_static { 25 | PermutationBuilderMRRR::PermutationBuilderMRRR(uint sample, BitSequenceBuilder * bmb) { 26 | this->sample = sample; 27 | this->bmb = bmb; 28 | } 29 | 30 | PermutationBuilderMRRR::~PermutationBuilderMRRR() { 31 | } 32 | 33 | Permutation * PermutationBuilderMRRR::build(uint * perm, uint len) const { 34 | return new PermutationMRRR(perm,len,sample,bmb); 35 | } 36 | 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/PermutationBuilderMRRR.h: -------------------------------------------------------------------------------- 1 | /* PermutationBuilderMRRR.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef PERMUTATIONBUILDERMRRR_H 22 | #define PERMUTATIONBUILDERMRRR_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace cds_static { 29 | 30 | class PermutationBuilderMRRR : public PermutationBuilder { 31 | public: 32 | PermutationBuilderMRRR(uint sample, BitSequenceBuilder * bmb); 33 | virtual ~PermutationBuilderMRRR(); 34 | virtual Permutation * build(uint * perm, uint len) const; 35 | protected: 36 | uint sample; 37 | BitSequenceBuilder * bmb; 38 | }; 39 | }; 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/PermutationMRRR.cpp: -------------------------------------------------------------------------------- 1 | /* PermutationMRRR.cpp 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Permutation 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | 23 | #include 24 | 25 | namespace cds_static { 26 | 27 | PermutationMRRR::PermutationMRRR(uint * elems, uint nelems, uint t, BitSequenceBuilder * bmb) { 28 | permutation = createPerm(elems, nelems, t, bmb); 29 | } 30 | 31 | PermutationMRRR::PermutationMRRR() { 32 | } 33 | 34 | PermutationMRRR::~PermutationMRRR() { 35 | destroyPerm(permutation); 36 | } 37 | 38 | size_t PermutationMRRR::getSize() const { 39 | return sizeof(PermutationMRRR)+sizeofPerm(permutation); 40 | } 41 | 42 | uint PermutationMRRR::pi(uint i) const { 43 | return getelemPerm(permutation,i); 44 | } 45 | 46 | uint PermutationMRRR::revpi(uint i) const { 47 | return inversePerm(permutation,i); 48 | } 49 | 50 | void PermutationMRRR::save(ofstream & fp) const { 51 | uint wr = MRRRPERM; 52 | saveValue(fp,wr); 53 | savePerm(permutation,fp); 54 | } 55 | 56 | PermutationMRRR * PermutationMRRR::load(ifstream & fp) { 57 | uint rd = loadValue(fp); 58 | if(rd!=MRRRPERM) return NULL; 59 | PermutationMRRR * ret = new PermutationMRRR(); 60 | ret->permutation = loadPerm(fp); 61 | return ret; 62 | } 63 | 64 | }; 65 | -------------------------------------------------------------------------------- /libcds/src/static/permutation/PermutationMRRR.h: -------------------------------------------------------------------------------- 1 | /* PermutationMRRR.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Permutation 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef _STATIC_PERMUTATION_MRRR_H 23 | #define _STATIC_PERMUTATION_MRRR_H 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace cds_utils; 30 | 31 | namespace cds_static { 32 | 33 | /** Wrapper for Diego Arroyuelo's implementation of Munro et al.'s permutations. 34 | * @author Francisco Claude 35 | */ 36 | class PermutationMRRR : public Permutation { 37 | public: 38 | PermutationMRRR(uint * elems, uint nelems, uint t, BitSequenceBuilder * bmb); 39 | virtual ~PermutationMRRR(); 40 | /** Computes the i-th element of the permutation */ 41 | virtual uint pi(uint i) const; 42 | /** Computes the inverse of i */ 43 | virtual uint revpi(uint i) const; 44 | /** Saves the permutation to fp, returns 0 in case of success */ 45 | virtual void save(ofstream & fp) const; 46 | /** Returns the size of the permutation */ 47 | virtual size_t getSize() const; 48 | /** Loads a static_permutation from fp */ 49 | static PermutationMRRR * load(ifstream & fp); 50 | protected: 51 | perm permutation; 52 | PermutationMRRR(); 53 | }; 54 | 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/.WaveletTree.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/src/static/sequence/.WaveletTree.cpp.swp -------------------------------------------------------------------------------- /libcds/src/static/sequence/.WaveletTree.h.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/src/static/sequence/.WaveletTree.h.swp -------------------------------------------------------------------------------- /libcds/src/static/sequence/.wt_node_internal.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/src/static/sequence/.wt_node_internal.cpp.swp -------------------------------------------------------------------------------- /libcds/src/static/sequence/.wt_node_internal.h.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/src/static/sequence/.wt_node_internal.h.swp -------------------------------------------------------------------------------- /libcds/src/static/sequence/.wt_node_leaf.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/src/static/sequence/.wt_node_leaf.cpp.swp -------------------------------------------------------------------------------- /libcds/src/static/sequence/BitmapsSequence.h: -------------------------------------------------------------------------------- 1 | /* static_sequence.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * static_sequence definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef _BITMAPSSEQUENCE_H 23 | #define _BITMAPSSEQUENCE_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | using namespace cds_utils; 32 | 33 | namespace cds_static 34 | { 35 | 36 | /** static_sequence represented using one bitmap per symbol, doesn't support efficient access 37 | * 38 | * @author Francisco Claude 39 | */ 40 | class BitmapsSequence : public Sequence 41 | { 42 | 43 | public: 44 | BitmapsSequence(uint * seq, size_t n, Mapper * am, BitSequenceBuilder * bsb); 45 | BitmapsSequence(const Array & a, Mapper * am, BitSequenceBuilder * bsb); 46 | 47 | virtual ~BitmapsSequence(); 48 | 49 | virtual size_t rank(uint c, size_t i) const; 50 | 51 | virtual size_t select(uint c, size_t i) const; 52 | virtual size_t selectNext(uint c, size_t i) const; 53 | 54 | virtual uint access(size_t i) const; 55 | 56 | virtual size_t getSize() const; 57 | 58 | virtual void save(ofstream & fp) const; 59 | 60 | /** Reads a bitmap determining the type */ 61 | static BitmapsSequence * load(ifstream & fp); 62 | 63 | protected: 64 | uint sigma; 65 | BitSequence ** bitmaps; 66 | Mapper * am; 67 | 68 | BitmapsSequence(); 69 | 70 | }; 71 | 72 | }; 73 | #endif /* _BITMAPSSEQUENCE_H */ 74 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp -f *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilder.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilder.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | 25 | #ifndef SEQUENCEBUILDER_H 26 | #define SEQUENCEBUILDER_H 27 | 28 | namespace cds_static { 29 | 30 | class SequenceBuilder { 31 | public: 32 | SequenceBuilder() { userCount=0; } 33 | virtual ~SequenceBuilder() {} 34 | virtual Sequence * build(uint * seq, size_t len)=0; 35 | virtual Sequence * build(const Array & seq)=0; 36 | virtual void use() { userCount++; } 37 | virtual void unuse() { userCount--; assert(userCount>=0); if(userCount==0) delete this; } 38 | 39 | protected: 40 | int userCount; 41 | }; 42 | }; 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderAlphPart.cpp: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderAlphPart.cpp 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | namespace cds_static { 24 | 25 | SequenceBuilderAlphPart::SequenceBuilderAlphPart(SequenceBuilder * groupIndexBuilder, SequenceBuilder * indexBuilder, uint cut) { 26 | this->groupIndexBuilder = groupIndexBuilder; 27 | this->indexBuilder = indexBuilder; 28 | this->cut = cut; 29 | groupIndexBuilder->use(); 30 | indexBuilder->use(); 31 | } 32 | 33 | SequenceBuilderAlphPart::~SequenceBuilderAlphPart() { 34 | groupIndexBuilder->unuse(); 35 | indexBuilder->unuse(); 36 | } 37 | 38 | Sequence * SequenceBuilderAlphPart::build(uint * sequence, size_t len) { 39 | return new SequenceAlphPart(sequence,len,cut,groupIndexBuilder,indexBuilder); 40 | } 41 | 42 | Sequence * SequenceBuilderAlphPart::build(const Array & seq) { 43 | return new SequenceAlphPart(seq,cut,groupIndexBuilder,indexBuilder); 44 | } 45 | }; 46 | 47 | 48 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderAlphPart.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderAlphPart.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #ifndef SequenceBuilderAlphPart_H 27 | #define SequenceBuilderAlphPart_H 28 | 29 | namespace cds_static { 30 | class SequenceBuilderAlphPart : public SequenceBuilder { 31 | public: 32 | SequenceBuilderAlphPart(SequenceBuilder * groupIndexBuilder, SequenceBuilder * indexBuilder, uint cut); 33 | virtual ~SequenceBuilderAlphPart(); 34 | virtual Sequence * build(uint * seq, size_t len); 35 | virtual Sequence * build(const Array & seq); 36 | 37 | protected: 38 | SequenceBuilder * groupIndexBuilder; 39 | SequenceBuilder * indexBuilder; 40 | uint cut; 41 | }; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderGMR.cpp: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderGMR.cpp 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | namespace cds_static { 24 | 25 | SequenceBuilderGMR::SequenceBuilderGMR(BitSequenceBuilder * bsb, SequenceBuilder * sqb, uint chunk_len) { 26 | this->bsb = bsb; 27 | this->sqb = sqb; 28 | this->chunk_len = chunk_len; 29 | bsb->use(); 30 | sqb->use(); 31 | } 32 | 33 | SequenceBuilderGMR::~SequenceBuilderGMR() { 34 | bsb->unuse(); 35 | sqb->unuse(); 36 | } 37 | 38 | Sequence * SequenceBuilderGMR::build(uint * sequence, size_t len) { 39 | uint cl = chunk_len; 40 | if(chunk_len==0) { 41 | uint s=0; 42 | for(size_t i=0;i 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #ifndef SequenceBuilderGMR_H 27 | #define SequenceBuilderGMR_H 28 | 29 | namespace cds_static { 30 | class SequenceBuilderGMR : public SequenceBuilder { 31 | public: 32 | SequenceBuilderGMR(BitSequenceBuilder * bsb, SequenceBuilder * sqb, uint chunk_len=0); 33 | virtual ~SequenceBuilderGMR(); 34 | virtual Sequence * build(uint * seq, size_t len); 35 | virtual Sequence * build(const Array & seq); 36 | 37 | protected: 38 | BitSequenceBuilder * bsb; 39 | SequenceBuilder * sqb; 40 | uint chunk_len; 41 | }; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderGMRChunk.cpp: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderGMRChunk.cpp 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | namespace cds_static { 24 | 25 | SequenceBuilderGMRChunk::SequenceBuilderGMRChunk(BitSequenceBuilder * bsb, PermutationBuilder * pmb) { 26 | this->bsb = bsb; 27 | this->pmb = pmb; 28 | bsb->use(); 29 | pmb->use(); 30 | } 31 | 32 | SequenceBuilderGMRChunk::~SequenceBuilderGMRChunk() { 33 | bsb->unuse(); 34 | pmb->unuse(); 35 | } 36 | 37 | Sequence * SequenceBuilderGMRChunk::build(uint * sequence, size_t len) { 38 | return new SequenceGMRChunk(sequence, len, bsb, pmb); 39 | } 40 | 41 | Sequence * SequenceBuilderGMRChunk::build(const Array & seq) { 42 | return new SequenceGMRChunk(seq, bsb, pmb); 43 | } 44 | 45 | }; 46 | 47 | 48 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderGMRChunk.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderGMRChunk.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #ifndef SequenceBuilderGMRChunk_H 28 | #define SequenceBuilderGMRChunk_H 29 | 30 | namespace cds_static { 31 | class SequenceBuilderGMRChunk : public SequenceBuilder { 32 | public: 33 | SequenceBuilderGMRChunk(BitSequenceBuilder * bsb, PermutationBuilder * pmb); 34 | virtual ~SequenceBuilderGMRChunk(); 35 | virtual Sequence * build(uint * seq, size_t len); 36 | virtual Sequence * build(const Array & seq); 37 | 38 | protected: 39 | BitSequenceBuilder * bsb; 40 | PermutationBuilder * pmb; 41 | }; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderStr.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderStr.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #ifndef SequenceBuilderStr_H 28 | #define SequenceBuilderStr_H 29 | 30 | namespace cds_static { 31 | class SequenceBuilderStr : public SequenceBuilder { 32 | public: 33 | SequenceBuilderStr(const string & options); 34 | virtual ~SequenceBuilderStr(); 35 | virtual Sequence * build(uint * seq, size_t len); 36 | virtual Sequence * build(const Array & seq); 37 | 38 | protected: 39 | virtual SequenceBuilder * getBuilder(const Array & seq); 40 | 41 | string str; 42 | }; 43 | }; 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderWaveletTree.cpp: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderWaveletTree.cpp 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | namespace cds_static { 24 | 25 | SequenceBuilderWaveletTree::SequenceBuilderWaveletTree(BitSequenceBuilder * bsb, Mapper * am, wt_coder * wc) { 26 | this->bsb = bsb; 27 | this->am = am; 28 | this->wc = wc; 29 | bsb->use(); 30 | am->use(); 31 | if(wc!=NULL) 32 | wc->use(); 33 | } 34 | 35 | SequenceBuilderWaveletTree::~SequenceBuilderWaveletTree() { 36 | bsb->unuse(); 37 | am->unuse(); 38 | if(wc!=NULL) 39 | wc->unuse(); 40 | } 41 | 42 | Sequence * SequenceBuilderWaveletTree::build(uint * sequence, size_t len) { 43 | Sequence * ret; 44 | if(wc==NULL) { 45 | wt_coder * wcaux = new wt_coder_huff(sequence,len,am); 46 | wcaux->use(); 47 | ret = new WaveletTree(sequence, len, wcaux, bsb, am); 48 | wcaux->unuse(); 49 | } else { 50 | ret = new WaveletTree(sequence, len, wc, bsb, am); 51 | } 52 | return ret; 53 | } 54 | 55 | Sequence * SequenceBuilderWaveletTree::build(const Array & seq) { 56 | Sequence * ret; 57 | if(wc==NULL) { 58 | wt_coder * wcaux = new wt_coder_huff(seq,am); 59 | wcaux->use(); 60 | ret = new WaveletTree(seq, wcaux, bsb, am); 61 | wcaux->unuse(); 62 | } else { 63 | ret = new WaveletTree(seq, wc, bsb, am); 64 | } 65 | return ret; 66 | } 67 | }; 68 | 69 | 70 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderWaveletTree.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderWaveletTree.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #ifndef SEQUENCEBUILDERWAVELETTREE_H 28 | #define SEQUENCEBUILDERWAVELETTREE_H 29 | 30 | namespace cds_static { 31 | class SequenceBuilderWaveletTree : public SequenceBuilder { 32 | public: 33 | SequenceBuilderWaveletTree(BitSequenceBuilder * bsb, Mapper * am, wt_coder * wc=NULL); 34 | virtual ~SequenceBuilderWaveletTree(); 35 | virtual Sequence * build(uint * seq, size_t len); 36 | virtual Sequence * build(const Array & seq); 37 | 38 | protected: 39 | BitSequenceBuilder * bsb; 40 | Mapper * am; 41 | wt_coder * wc; 42 | }; 43 | }; 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderWaveletTreeNoptrs.cpp: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderWaveletTreeNoptrs.cpp 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | namespace cds_static { 24 | 25 | SequenceBuilderWaveletTreeNoptrs::SequenceBuilderWaveletTreeNoptrs(BitSequenceBuilder * bsb, Mapper * am) { 26 | this->bsb = bsb; 27 | this->am = am; 28 | bsb->use(); 29 | am->use(); 30 | } 31 | 32 | SequenceBuilderWaveletTreeNoptrs::~SequenceBuilderWaveletTreeNoptrs() { 33 | bsb->unuse(); 34 | am->unuse(); 35 | } 36 | 37 | Sequence * SequenceBuilderWaveletTreeNoptrs::build(uint * sequence, size_t len) { 38 | return new WaveletTreeNoptrs(sequence, len, bsb, am); 39 | } 40 | 41 | Sequence * SequenceBuilderWaveletTreeNoptrs::build(const Array & seq) { 42 | return new WaveletTreeNoptrs(seq, bsb, am); 43 | } 44 | }; 45 | 46 | 47 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceBuilderWaveletTreeNoptrs.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderWaveletTreeNoptrs.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #ifndef SEQUENCEBUILDERWAVELETTREENOPTRS_H 28 | #define SEQUENCEBUILDERWAVELETTREENOPTRS_H 29 | 30 | namespace cds_static { 31 | class SequenceBuilderWaveletTreeNoptrs : public SequenceBuilder { 32 | public: 33 | SequenceBuilderWaveletTreeNoptrs(BitSequenceBuilder * bsb, Mapper * am); 34 | virtual ~SequenceBuilderWaveletTreeNoptrs(); 35 | virtual Sequence * build(uint * seq, size_t len); 36 | virtual Sequence * build(const Array & seq); 37 | 38 | protected: 39 | BitSequenceBuilder * bsb; 40 | Mapper * am; 41 | }; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/SequenceGMR.h: -------------------------------------------------------------------------------- 1 | /* SequenceGMR.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * GMR 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef SEQUENCEGMR_H 23 | #define SEQUENCEGMR_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace cds_utils; 34 | namespace cds_static { 35 | //using namespace std; 36 | 37 | class SequenceGMR : public Sequence { 38 | public: 39 | /** Builds the GMR structure. 40 | * @param sequence Sequence of unsigned ints 41 | * @param n length of the sequence 42 | * @param chunk_length length of the regular partitioning (called chunks in the paper) 43 | * @param bmb builder for the bitmap B (as called in the paper) 44 | * @param ssb builder for the representation used for each chunk. 45 | */ 46 | SequenceGMR(uint * sequence, size_t n, uint chunk_length, BitSequenceBuilder * bmb, SequenceBuilder * ssb); 47 | SequenceGMR(const Array & sequence, uint chunk_length, BitSequenceBuilder * bmb, SequenceBuilder * ssb); 48 | 49 | ~SequenceGMR(); 50 | virtual size_t rank(uint c, size_t j) const; 51 | virtual size_t select(uint c, size_t j) const; 52 | virtual uint access(size_t j) const; 53 | virtual size_t getSize() const; 54 | virtual void save(ofstream & fp) const; 55 | /** Loads the SequenceGMR object from the stream. 56 | */ 57 | static SequenceGMR * load(ifstream & fp); 58 | 59 | protected: 60 | SequenceGMR(); 61 | void build(uint * sequence, BitSequenceBuilder * bmb, SequenceBuilder * ssb); 62 | uint * get_ones(uint * sequence); 63 | 64 | uint sigma, chunk_length; 65 | Sequence ** chunk; 66 | BitSequence * B; 67 | }; 68 | 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_coder.cpp: -------------------------------------------------------------------------------- 1 | /* wt_coder.cpp 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_coder definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | wt_coder::wt_coder() { 28 | user_count=0; 29 | } 30 | 31 | void wt_coder::use() { 32 | user_count++; 33 | } 34 | 35 | void wt_coder::unuse() { 36 | user_count--; 37 | if(user_count==0) delete this; 38 | } 39 | 40 | wt_coder * wt_coder::load(ifstream & fp) { 41 | uint rd = loadValue(fp); 42 | size_t pos = fp.tellg(); 43 | fp.seekg(pos-sizeof(uint)); 44 | switch(rd) { 45 | case WT_CODER_HUFF_HDR: return wt_coder_huff::load(fp); 46 | case WT_CODER_BINARY_HDR: return wt_coder_binary::load(fp); 47 | } 48 | return NULL; 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_coder.h: -------------------------------------------------------------------------------- 1 | /* wt_coder.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_coder definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef wt_coder_h 23 | #define wt_coder_h 24 | 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | namespace cds_static 31 | { 32 | 33 | #define WT_CODER_HUFF_HDR 2 34 | #define WT_CODER_BINARY_HDR 3 35 | 36 | class wt_coder_binary; 37 | class wt_coder_huff; 38 | 39 | /** Coder that defines the shape of a wavelet tree 40 | * 41 | * @author Francisco Claude 42 | */ 43 | class wt_coder 44 | { 45 | public: 46 | wt_coder(); 47 | virtual void use(); 48 | virtual void unuse(); 49 | virtual ~wt_coder() {}; 50 | /** Tells if at level l the symbol is represented by a one or a zero */ 51 | virtual bool is_set(uint symbol, uint l) const=0; 52 | /** Tells if the path of symbol becomes unique at level l */ 53 | virtual bool done(uint symbol, uint l) const =0; 54 | /** Returns the size of the coder */ 55 | virtual size_t getSize() const = 0; 56 | /** Returns the depth of the tree */ 57 | virtual uint depth() const 58 | { 59 | return -1; // Implemented in wt_coder_binary 60 | } 61 | /** Saves the coder to a file, returns 0 in case of success */ 62 | virtual void save(ofstream & fp) const = 0; 63 | /** Loads a coder from a file, returns NULL in case of error */ 64 | static wt_coder * load(ifstream & fp); 65 | protected: 66 | uint user_count; 67 | }; 68 | 69 | }; 70 | 71 | #include 72 | #include 73 | #endif 74 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_coder_binary.h: -------------------------------------------------------------------------------- 1 | /* wt_coder_binary.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_coder_binary definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef wt_coder_binary_h 23 | #define wt_coder_binary_h 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace std; 30 | 31 | namespace cds_static 32 | { 33 | 34 | /** Considers the binary representation of the symbols as the code 35 | * 36 | * @author Francisco Claude 37 | */ 38 | class wt_coder_binary: public wt_coder 39 | { 40 | public: 41 | wt_coder_binary(const Array & a, Mapper *am); 42 | /** Buils a wt_coder_binary using the sequence of length n and the alphabet_mapper 43 | * to determine the length of the binary codes */ 44 | wt_coder_binary(uint * seq, size_t n, Mapper * am); 45 | wt_coder_binary(uchar * seq, size_t n, Mapper * am); 46 | virtual ~wt_coder_binary(); 47 | virtual bool is_set(uint symbol, uint l) const; 48 | virtual bool done(uint symbol, uint l) const; 49 | virtual uint depth() const{ return h; } 50 | virtual size_t getSize() const; 51 | virtual void save(ofstream & fp) const; 52 | static wt_coder_binary * load(ifstream & fp); 53 | 54 | protected: 55 | wt_coder_binary(); 56 | uint h; 57 | }; 58 | }; 59 | #endif 60 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_coder_huff.h: -------------------------------------------------------------------------------- 1 | /* wt_coder_huff.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_coder_huff definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef wt_coder_huff_h 23 | #define wt_coder_huff_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace cds_static 31 | { 32 | 33 | /** Uses huffman codes to determine the shape of the wavelet tree 34 | * 35 | * @author Francisco Claude 36 | */ 37 | class wt_coder_huff: public wt_coder 38 | { 39 | public: 40 | /** Buils a wt_coder_huff using the sequence of length n and the alphabet_mapper 41 | * to determine the huffman codes */ 42 | wt_coder_huff(const Array & a, Mapper *am); 43 | wt_coder_huff(uint *symbs, size_t n, Mapper * am); 44 | wt_coder_huff(uchar *symbs, size_t n, Mapper * am); 45 | virtual ~wt_coder_huff(); 46 | virtual bool is_set(uint symbol, uint l) const; 47 | virtual bool done(uint symbol, uint l) const; 48 | virtual size_t getSize() const; 49 | virtual void save(ofstream & fp) const; 50 | static wt_coder_huff * load(ifstream & fp); 51 | //uint * get_buffer(uint symbol, uint *n); 52 | 53 | protected: 54 | wt_coder_huff(); 55 | HuffmanCoder * hc; 56 | uint maxBuffer; 57 | }; 58 | }; 59 | #endif 60 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_node.cpp: -------------------------------------------------------------------------------- 1 | /* wt_node.cpp 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_node 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | wt_node * wt_node::load(ifstream & fp) { 28 | uint rd = loadValue(fp); 29 | if(rd==WT_NODE_NULL_HDR) return NULL; 30 | size_t pos = fp.tellg(); 31 | fp.seekg(pos-sizeof(uint)); 32 | switch(rd) { 33 | case WT_NODE_INTERNAL_HDR: return wt_node_internal::load(fp); 34 | case WT_NODE_LEAF_HDR: return wt_node_leaf::load(fp); 35 | } 36 | return NULL; 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_node.h: -------------------------------------------------------------------------------- 1 | /* wt_node.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_node 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef wt_node_h 23 | #define wt_node_h 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace cds_utils; 30 | 31 | namespace cds_static 32 | { 33 | 34 | #define WT_NODE_NULL_HDR 0 35 | #define WT_NODE_INTERNAL_HDR 2 36 | #define WT_NODE_LEAF_HDR 3 37 | 38 | /** Base clase for nodes in the wavelet tree 39 | * 40 | * @author Francisco Claude 41 | */ 42 | class wt_node 43 | { 44 | public: 45 | virtual ~wt_node() {} 46 | virtual size_t rank(uint symbol, size_t pos, uint l, wt_coder * c) const = 0; 47 | virtual size_t select(uint symbol, size_t pos, uint l, wt_coder * c) const = 0; 48 | virtual uint access(size_t pos) const = 0; 49 | virtual uint access(size_t pos, size_t & rankp) const = 0; 50 | virtual size_t getSize() const = 0; 51 | virtual void save(ofstream & fp) const = 0; 52 | static wt_node * load(ifstream & fp); 53 | }; 54 | 55 | }; 56 | 57 | #include 58 | #include 59 | #endif 60 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_node_internal.h: -------------------------------------------------------------------------------- 1 | /* wt_node_internal.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_node_internal 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef wt_node_internal_h 23 | #define wt_node_internal_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace cds_static 32 | { 33 | 34 | /** Class for representing internal nodes 35 | * 36 | * @author Francisco Claude 37 | */ 38 | class wt_node_internal: public wt_node 39 | { 40 | public: 41 | wt_node_internal(uint * seq, size_t n, uint l, wt_coder * c, BitSequenceBuilder * bmb); 42 | wt_node_internal(uchar * seq, size_t n, uint l, wt_coder * c, BitSequenceBuilder * bmb, size_t left, uint * done); 43 | virtual ~wt_node_internal(); 44 | virtual size_t rank(uint symbol, size_t pos, uint level, wt_coder * c) const; 45 | //virtual size_t rankLessThan(uint &symbol, size_t pos) const; 46 | virtual size_t select(uint symbol, size_t pos, uint level, wt_coder * c) const; 47 | virtual uint access(size_t pos) const; 48 | virtual uint access(size_t pos, size_t & rankp) const; 49 | virtual size_t getSize() const; 50 | virtual void save(ofstream & fp) const; 51 | static wt_node_internal * load(ifstream & fp); 52 | 53 | protected: 54 | wt_node_internal(); 55 | wt_node *left_child, *right_child; 56 | BitSequence * bitmap; 57 | //uint length; 58 | }; 59 | }; 60 | #endif 61 | -------------------------------------------------------------------------------- /libcds/src/static/sequence/wt_node_leaf.h: -------------------------------------------------------------------------------- 1 | /* wt_node_leaf.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * wt_node_leaf 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #ifndef wt_node_leaf_h 23 | #define wt_node_leaf_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace cds_static 32 | { 33 | 34 | /** Class for representing leaves of the wavelet tree. 35 | * 36 | * @author Francisco Claude 37 | */ 38 | class wt_node_leaf: public wt_node 39 | { 40 | public: 41 | wt_node_leaf(uint symbol, size_t count); 42 | virtual ~wt_node_leaf(); 43 | virtual size_t rank(uint symbol, size_t pos, uint l, wt_coder * c) const; 44 | virtual size_t select(uint symbol, size_t pos, uint l, wt_coder * c) const; 45 | virtual uint access(size_t pos) const; 46 | virtual uint access(size_t pos, size_t &rank) const; 47 | virtual size_t getSize() const; 48 | virtual void save(ofstream & fp) const; 49 | static wt_node_leaf * load(ifstream & fp); 50 | 51 | protected: 52 | wt_node_leaf(); 53 | uint symbol; 54 | size_t count; 55 | }; 56 | }; 57 | #endif 58 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/LCP_DAC.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef LCP_DAC_H 21 | #define LCP_DAC_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cds_static{ 27 | 28 | class LCP_DAC: public LCP{ 29 | 30 | private: 31 | size_t *next_p; //usefull for get_seq_LCP 32 | factorization *rep; 33 | LCP_DAC(); 34 | 35 | public: 36 | size_t n; 37 | 38 | /* LCP encoding using Susana's static factorization, 39 | * @param csa The compressed suffix array of the text 40 | * @param text The text 41 | * @param n The length of the text 42 | * */ 43 | LCP_DAC(TextIndex *csa, char *text, size_t n); 44 | virtual size_t get_LCP(size_t i, TextIndex *csa) const; 45 | virtual size_t get_seq_LCP(size_t i, TextIndex *csa, size_t **next_pos, size_t *n_next, bool dir) const; 46 | virtual size_t getSize() const; 47 | virtual void save(ofstream & fp) const; 48 | static LCP_DAC * load(ifstream & fp); 49 | virtual ~LCP_DAC(); 50 | }; 51 | }; 52 | 53 | #endif 54 | 55 | 56 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/LCP_DAC_VAR.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef LCP_DAC_VAR_H 21 | #define LCP_DAC_VAR_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cds_static{ 27 | 28 | class LCP_DAC_VAR: public LCP{ 29 | private: 30 | LCP_DAC_VAR(); 31 | 32 | factorization_var *rep; 33 | size_t *next_p_var; 34 | 35 | public: 36 | size_t n; 37 | 38 | /*Compute the "optimal" block size given an array of frequencies 39 | * @param max_lcp Maximun value in the array 40 | * @param frec_acu Array that contain the acumulate frequency 41 | * @param kvalues Array where the block sizes obtained will be stored 42 | * @param nkvalues Size of the array kvalues 43 | * */ 44 | void calc_kvalues(uint max_lcp, uint *frec_acu, ushort **kvalues, uint *nkvalues) const; 45 | 46 | /* LCP encoding using Susana's factorization_var, 47 | * @param csa The compressed suffix array of the text 48 | * @param text The text 49 | * @param n The length of the text 50 | * */ 51 | LCP_DAC_VAR(TextIndex *csa, char *text, size_t n); 52 | virtual size_t get_LCP(size_t i, TextIndex *csa) const; 53 | virtual size_t get_seq_LCP(size_t i, TextIndex *csa, size_t **next_pos, size_t *n_next, bool dir) const; 54 | virtual size_t getSize() const; 55 | virtual void save(ofstream & fp) const; 56 | static LCP_DAC_VAR * load(ifstream & fp); 57 | virtual ~LCP_DAC_VAR(); 58 | }; 59 | 60 | }; 61 | #endif 62 | 63 | 64 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/LCP_FMN.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef LCP_FMN_H 21 | #define LCP_FMN_H 22 | 23 | #include 24 | #include 25 | 26 | using namespace cds_static; 27 | 28 | namespace cds_static{ 29 | 30 | class LCP_FMN: public LCP{ 31 | private: 32 | LCP_FMN(); 33 | virtual void generate_OZ(BitSequence *U, uint **O, uint **Z, uint length); 34 | 35 | BitSequence *O, *Z; 36 | size_t b_length; //length of the bitmaps 37 | size_t OZ_type; 38 | 39 | public: 40 | 41 | /*Johannes, Veli & Gonzalo LCP encode 42 | * @param csa The compressed suffix array of the text 43 | * @param text The text 44 | * @param n The length of the text 45 | * @param op_rs Choose rank/select implementation that will be used (must be RRR02_HDR or SDARRAY_HDR) 46 | * */ 47 | LCP_FMN(TextIndex *csa, char *text, size_t n, size_t op_rs=RRR02_HDR); 48 | 49 | LCP_FMN(LCP *lcp, TextIndex *csa, size_t n, size_t op_rs=RRR02_HDR); 50 | 51 | /**Return LCP[i]*/ 52 | virtual size_t get_LCP(size_t i, TextIndex *csa) const; 53 | 54 | /**Return LCP[i], being faster if sequential acceses to the LCP had been done*/ 55 | virtual size_t get_seq_LCP(size_t i, TextIndex *csa, size_t **next_pos, size_t *n_next, bool dir) const; 56 | 57 | /** Returns the size of the structure in bytes */ 58 | virtual size_t getSize() const; 59 | 60 | /** Stores the structure given a file pointer, return 0 in case of success */ 61 | virtual void save(ofstream & fp) const; 62 | 63 | /** Reads a LCP determining the type */ 64 | static LCP_FMN * load(ifstream & fp); 65 | 66 | virtual ~LCP_FMN(); 67 | }; 68 | }; 69 | 70 | #endif 71 | 72 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/LCP_PT.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef LCP_PT_H 21 | #define LCP_PT_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cds_static{ 27 | 28 | class LCP_PT: public LCP{ 29 | private: 30 | LCP_PT(); 31 | 32 | virtual int calc_delta(unsigned int i, unsigned int j) const; 33 | 34 | int logv; 35 | size_t length; 36 | int mask; 37 | int v; 38 | int m; /*size of rev_ess*/ 39 | int *rev_cover; 40 | int *delta; 41 | int cover_size; 42 | int *rev_ess; 43 | RMQ_succinct *rmq; 44 | 45 | public: 46 | /*Puglisi and Turpin encoding of the LCP, 47 | * @param csa The compressed suffix array of the text 48 | * @param text The text 49 | * @param n The length of the text 50 | * @param _logv logarithm (base 2) of the period of the difference cover you would like to use. Valid values for "logv" are 2,3,4,5,6,7 and 8 51 | * */ 52 | LCP_PT(TextIndex *csa, char *text, size_t n, int _logv=8); 53 | virtual size_t get_LCP(size_t i, TextIndex *csa) const; 54 | virtual size_t get_seq_LCP(size_t i, TextIndex *csa, size_t **next_pos, size_t *n_next, bool dir) const; 55 | virtual size_t getSize() const; 56 | virtual void save(ofstream & fp) const; 57 | static LCP_PT * load(ifstream & fp); 58 | virtual ~LCP_PT(); 59 | }; 60 | }; 61 | #endif 62 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/LCP_PhiSpare.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef LCP_PHISPARE_H 21 | #define LCP_PHISPARE_H 22 | 23 | #include 24 | 25 | namespace cds_static{ 26 | 27 | class LCP_PhiSpare: public LCP{ 28 | private: 29 | int q; 30 | size_t n; //length of LCP 31 | int *plcp; //psi lcp 32 | 33 | LCP_PhiSpare(); 34 | 35 | public: 36 | /*Karkkainen, Manzini, and Puglisi encoding of the LCP, 37 | * @param csa The compressed suffix array of the text 38 | * @param text The text 39 | * @param n The length of the text 40 | * @param _q The sample period to use (if q = -1 its mean that we will not use any sample) 41 | * */ 42 | LCP_PhiSpare(TextIndex *csa, char *text, size_t _n, int _q = 32); 43 | virtual size_t get_LCP(size_t i, TextIndex *csa) const; 44 | virtual size_t get_seq_LCP(size_t i, TextIndex *csa, size_t **next_pos, size_t *n_next, bool dir) const; 45 | virtual size_t getSize() const; 46 | virtual void save(ofstream & fp) const; 47 | static LCP_PhiSpare * load(ifstream & fp); 48 | virtual ~LCP_PhiSpare(); 49 | }; 50 | }; 51 | #endif 52 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/LCP_Sad.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef LCP_SAD_H 21 | #define LCP_SAD_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cds_static{ 27 | class LCP_Sad: public LCP{ 28 | private: 29 | LCP_Sad(); 30 | size_t U_type; 31 | 32 | public: 33 | BitSequence *U; 34 | size_t U_length; //length of bitmap U 35 | 36 | /*Create Sadakane encoding of the LCP, that use 2n+o(n) bits, 37 | * @param csa The compressed suffix array of the text 38 | * @param text The text 39 | * @param n The length of the text 40 | * */ 41 | LCP_Sad(TextIndex *csa, char *text, size_t n, size_t op_rs = BRW32_HDR); 42 | 43 | /*Create the LCP representation starting from a precomputed LCP array*/ 44 | LCP_Sad(LCP *lcp, TextIndex *csa, size_t n, size_t op_rs = BRW32_HDR); 45 | 46 | /**Return LCP[i]*/ 47 | virtual size_t get_LCP(size_t i, TextIndex *csa) const; 48 | 49 | /**Return LCP[i], being faster if sequential acceses to the LCP had been done*/ 50 | virtual size_t get_seq_LCP(size_t i, TextIndex *csa, size_t **next_pos, size_t *n_next, bool dir) const; 51 | 52 | /** Returns the size of the structure in bytes */ 53 | virtual size_t getSize() const; 54 | 55 | /** Stores the structure given a file pointer*/ 56 | virtual void save(ofstream & fp) const; 57 | 58 | /** Reads a LCP determining the type */ 59 | static LCP_Sad * load(ifstream & fp); 60 | 61 | virtual ~LCP_Sad(); 62 | }; 63 | }; 64 | 65 | #endif 66 | 67 | 68 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/LCP_naive.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | #ifndef LCP_NAIVE_H 20 | #define LCP_NAIVE_H 21 | 22 | #include 23 | 24 | namespace cds_static{ 25 | 26 | class LCP_naive: public LCP{ 27 | private: 28 | LCP_naive(); 29 | size_t *lcp_array; 30 | size_t b; 31 | size_t length; 32 | 33 | public: 34 | 35 | LCP_naive(TextIndex *csa, char *text, size_t n); 36 | 37 | /**Return LCP[i]*/ 38 | virtual size_t get_LCP(size_t i, TextIndex *csa) const; 39 | 40 | /**Return LCP[i], being faster if sequential acceses to the LCP had been done*/ 41 | virtual size_t get_seq_LCP(size_t i, TextIndex *csa, size_t **next_pos, size_t *n_next, bool dir) const; 42 | 43 | /** Returns the size of the structure in bytes */ 44 | virtual size_t getSize() const; 45 | 46 | /** Stores the structure given a file pointer, return 0 in case of success */ 47 | virtual void save(ofstream & fp) const; 48 | 49 | /** Reads a LCP determining the type */ 50 | static LCP_naive * load(ifstream & fp); 51 | 52 | virtual ~LCP_naive(); 53 | }; 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp -f *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/NPR.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #include 21 | 22 | namespace cds_static{ 23 | NPR * NPR::load(ifstream & fp){ 24 | size_t r = loadValue(fp); 25 | size_t pos = fp.tellg(); 26 | fp.seekg(pos-sizeof(size_t)); 27 | cout << "Loading NPR "<< r << endl; 28 | switch(r) { 29 | case FMN_NPR: return NPR_FMN::load(fp); 30 | case CN_NPR: return NPR_CN::load(fp); 31 | } 32 | return NULL; 33 | } 34 | 35 | }; 36 | 37 | 38 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/NPR.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef NPR_H 21 | #define NPR_H 22 | 23 | #include 24 | 25 | namespace cds_static{ 26 | 27 | static const size_t FMN_NPR = 2; 28 | static const size_t CN_NPR = 3; 29 | 30 | class NPR{ 31 | public: 32 | size_t npr_type; 33 | 34 | virtual ~NPR() {}; 35 | 36 | // Return the position of the next smaller value of i (NSV[i]) 37 | virtual size_t find_NSV(size_t i, TextIndex *csa, LCP *lcp) const= 0; 38 | 39 | // Return the position of the previous smaller value of i plus one (PSV[i]+1) 40 | virtual size_t find_PSV(size_t i, TextIndex *csa, LCP *lcp) const= 0; 41 | 42 | //Return the first previous position, from i, that contains a value < d 43 | virtual size_t bwd_PSV(size_t i, TextIndex *csa, LCP *lcp, size_t d) const= 0; 44 | 45 | //Return the first next position, from i, that contains a value < d 46 | virtual size_t fwd_NSV(size_t i, TextIndex *csa, LCP *lcp, size_t d) const= 0; 47 | 48 | //Return the range minimum query over the LCP array, between the positions x and y 49 | virtual size_t find_RMQ(size_t x, size_t y, TextIndex *csa, LCP *lcp) const= 0; 50 | 51 | //Return the size, in bytes, of the NPR structure 52 | virtual size_t getSize() const = 0; 53 | 54 | virtual void save(ofstream & fp) const=0; 55 | 56 | static NPR * load(ifstream & fp); 57 | }; 58 | 59 | }; 60 | #include 61 | #include 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/NPR_FMN.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef NPR_FMN_H 21 | #define NPR_FMN_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace cds_static{ 29 | 30 | class NPR_FMN: public NPR{ 31 | private: 32 | NSV *nsv; 33 | PSV *psv; 34 | RMQ_succinct_lcp *rmq; 35 | 36 | NPR_FMN(); 37 | 38 | public: 39 | 40 | /*NPR Data structure base on Fisher, Makinnen, and Navarro "Faster Entropy-Bounded Compressed Suffix Trees" 41 | * @param lcp Any LCP array data structure 42 | * @param block_Size Block size that will be used 43 | * @param csa The compresses suffix array 44 | * @param levels Number of levels that the recursion will use. (in general is better to use only 2 or 3 levels) 45 | * */ 46 | NPR_FMN(LCP *lcp, size_t block_Size, TextIndex *csa, size_t levels = 2); 47 | 48 | virtual ~NPR_FMN(); 49 | 50 | virtual size_t find_NSV(size_t i, TextIndex *csa, LCP *lcp) const; 51 | 52 | virtual size_t find_PSV(size_t i, TextIndex *csa, LCP *lcp) const; 53 | 54 | virtual size_t bwd_PSV(size_t i, TextIndex *csa, LCP *lcp, size_t d) const; 55 | 56 | virtual size_t fwd_NSV(size_t i, TextIndex *csa, LCP *lcp, size_t d) const; 57 | 58 | virtual size_t find_RMQ(size_t x, size_t y, TextIndex *csa, LCP *lcp) const; 59 | 60 | virtual size_t getSize() const; 61 | 62 | virtual void save(ofstream & fp) const; 63 | 64 | static NPR_FMN * load(ifstream & fp); 65 | }; 66 | 67 | }; 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/NSV.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef NSV_H 21 | #define NSV_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cds_static{ 27 | class NSV{ 28 | 29 | private: 30 | NSV(); 31 | virtual void create_first_level(LCP *lcp, TextIndex *csa); 32 | virtual void create_level_r(LCP *lcp, size_t level, TextIndex *csa); 33 | virtual void create_last_level(LCP *lcp, TextIndex *csa); 34 | virtual size_t find_NSV_r(size_t v, size_t level, TextIndex *csa, LCP *lcp) const; 35 | 36 | size_t r; /*levels*/ 37 | size_t b; /*block size*/ 38 | size_t n; /*number of element of lcp*/ 39 | BitSequence **P; /*bitarray with the pioneer for each level*/ 40 | BitSequence **R; /*bitarray with the pioneer and their answers*/ 41 | size_t *A; /*stored values for the last level*/ 42 | size_t b_A; /*bits needed per value in A*/ 43 | 44 | 45 | public: 46 | 47 | /*NSV Data structure base on Fisher, Makinnen, and Navarro "Faster Entropy-Bounded Compressed Suffix Trees" 48 | * @param lcp Any LCP array data structure 49 | * @param levels Number of levels that the recursion will use (in general is better to use only 2 or 3 levels). 50 | * @param block Block size that will be used 51 | * @param csa The compresses suffix array*/ 52 | NSV(LCP *lcp, size_t levels, size_t block, TextIndex *csa); 53 | 54 | //return the position where is the NSV of v 55 | virtual size_t find_NSV(size_t v, TextIndex *csa, LCP *lcp) const; 56 | 57 | //memory use for NSV in bytes 58 | virtual size_t getSize() const; 59 | 60 | virtual void save(ofstream & fp) const; 61 | 62 | static NSV* load(ifstream & fp); 63 | 64 | virtual ~NSV(); 65 | }; 66 | 67 | }; 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/PSV.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #ifndef PSV_H 21 | #define PSV_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cds_static{ 27 | class PSV{ 28 | 29 | private: 30 | PSV(); 31 | virtual void create_first_level(LCP *lcp, TextIndex *csa); 32 | virtual void create_level_r(LCP *lcp, size_t level, TextIndex *csa); 33 | virtual void create_last_level(LCP *lcp, TextIndex *csa); 34 | virtual size_t find_PSV_r(size_t v, size_t level, TextIndex *csa, LCP *lcp) const; 35 | 36 | size_t r; /*levels*/ 37 | size_t b; /*block size*/ 38 | size_t n; /*number of element of lcp*/ 39 | BitSequence **P; /*bitarray with the pioneer for each level*/ 40 | BitSequence **R; /*bitarray with the pioneer and their answers*/ 41 | size_t *A; /*stored values for the last level*/ 42 | size_t b_A; /*bits needed per value in A*/ 43 | 44 | public: 45 | /*PSV Data structure base on Fisher, Makinnen, and Navarro "Faster Entropy-Bounded Compressed Suffix Trees" 46 | * @param lcp Any LCP array data structure 47 | * @param levels Number of levels that the recursion will use (in general is better to use only 2 or 3 levels). 48 | * @param block Block size that will be use 49 | * @param csa The compresses suffix array*/ 50 | PSV(LCP *lcp, size_t levels, size_t block, TextIndex *csa); 51 | 52 | //Return the position (plus 1) where is the PSV of v 53 | virtual size_t find_PSV(size_t v, TextIndex *SA, LCP *lcp) const; 54 | 55 | //Memory use for PSV in bytes 56 | virtual size_t getSize() const; 57 | 58 | virtual void save(ofstream & fp) const; 59 | 60 | static PSV* load(ifstream & fp); 61 | 62 | virtual ~PSV(); 63 | }; 64 | 65 | }; 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/SuffixTree.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | #include 21 | 22 | namespace cds_static{ 23 | 24 | SuffixTree * SuffixTree::load(ifstream & fp){ 25 | size_t r = loadValue(fp); 26 | size_t pos = fp.tellg(); 27 | fp.seekg(pos-sizeof(size_t)); 28 | cout << "Loading "<< r << endl; 29 | switch(r) { 30 | case CSTY: return SuffixTreeY::load(fp); 31 | } 32 | return NULL; 33 | } 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/factorization.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | /*----------------------------------------------------------------------- 21 | Factorizacion version 22 | ------------------------------------------------------------------------*/ 23 | #ifndef _FACTORIZATION 24 | #define _FACTORIZATION 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace cds_static{ 34 | 35 | class factorization{ 36 | private: 37 | factorization(); 38 | public: 39 | uint listLength; //longitud de la lista 40 | byte nLevels; //numero de niveles de arrays 41 | uint * levelsIndex; //inicio de cada array 42 | byte * levels; //array con los bytes 43 | BitSequence * bS; //bitmap para indicar fin de codigo 44 | uint * rankLevels; //rank de 1s hasta el principio de cada array 45 | 46 | /*Susana implementation of Directly Addressable Variable-Length Codes with blocks of size 4 47 | * @param list Array with the values 48 | * @param l_Length Size of the array 49 | * */ 50 | factorization(uint *list,uint l_Length); 51 | virtual uint access(uint param); 52 | virtual uint access_seq(uint param, size_t *next_pos, bool dir); 53 | virtual void save(ofstream & fp); 54 | virtual uint getSize(); 55 | static factorization* load(ifstream & fp); 56 | virtual ~factorization(); 57 | }; 58 | }; 59 | #endif 60 | -------------------------------------------------------------------------------- /libcds/src/static/suffixtree/factorization_var.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | 20 | /*----------------------------------------------------------------------- 21 | Factorizacion with Variable block size 22 | ------------------------------------------------------------------------*/ 23 | #ifndef _FACTORIZATION_VAR 24 | #define _FACTORIZATION_VAR 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace cds_static{ 34 | 35 | class factorization_var{ 36 | private: 37 | factorization_var(); 38 | public: 39 | uint tamCode; 40 | uint * iniLevel; 41 | ushort * base; 42 | ushort * base_bits; 43 | uint * tablebase; 44 | uint tamtablebase; 45 | uint listLength; //list length 46 | byte nLevels; //number of levels 47 | uint * levelsIndex; //start point of each array 48 | uint * levels; //array with the bytes 49 | BitSequence * bS; //bitmap para indicar fin de codigo 50 | uint * rankLevels; //rank de 1s hasta el principio de cada array 51 | 52 | 53 | /*Susana implementation of Directly Addressable Variable-Length Codes with variable length blocks 54 | * @param list Array with the values 55 | * @param l_Length Size of the array 56 | * @param kvalues Array with the block length for each level 57 | * @param nkvalues Length of the array kvalues 58 | * */ 59 | factorization_var(uint *list, uint l_Length, ushort* kvalues, uint nkvalues); 60 | virtual uint access(uint param); 61 | virtual uint access_seq(uint param, size_t *next_pos, bool dir); 62 | virtual uint getSize(); 63 | virtual void save(ofstream & fp); 64 | static factorization_var* load(ifstream & fp); 65 | virtual ~factorization_var(); 66 | }; 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /libcds/src/static/textindex/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @cp -f *.h ../../../includes/ 4 | -------------------------------------------------------------------------------- /libcds/src/static/textindex/TextIndex.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2010, Rodrigo Cánovas, all rights reserved. 2 | * 3 | *This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | * 17 | */ 18 | 19 | /* General interface for using the compressed index libraries */ 20 | 21 | #include 22 | 23 | namespace cds_static{ 24 | 25 | /** Reads a text index determining the type */ 26 | TextIndex * TextIndex::load(ifstream & fp){ 27 | uint r = loadValue(fp); 28 | size_t pos = fp.tellg(); 29 | fp.seekg(pos-sizeof(uint)); 30 | switch(r) { 31 | case CSA_HDR: return TextIndexCSA::load(fp); 32 | } 33 | return NULL; 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /libcds/src/static/textindex/comparray4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/src/static/textindex/comparray4.cpp -------------------------------------------------------------------------------- /libcds/src/static/textindex/comparray4.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/migumar2/libCSD/568bf8a876684d871b97c93b4322ddf71eb830b3/libcds/src/static/textindex/comparray4.h -------------------------------------------------------------------------------- /libcds/src/static/textindex/mmap.h: -------------------------------------------------------------------------------- 1 | 2 | /* mman.h 3 | Copyright (C) 2005, K. Sadakane, all rights reserved. 4 | 5 | This file contains an implementation of memory manager 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | 21 | */ 22 | 23 | #ifndef _MYMMAP_H_ 24 | #define _MYMMAP_H_ 25 | 26 | 27 | #ifdef WIN32 28 | #include 29 | #else 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #endif 38 | 39 | #ifdef WIN32 40 | #define PAGE_READONLY 0x02 41 | #define SECTION_MAP_READ 0x0004 42 | #define FILE_MAP_READ SECTION_MAP_READ 43 | #endif 44 | 45 | namespace cds_static{ 46 | 47 | typedef struct { 48 | void *addr; 49 | int len; 50 | #ifdef WIN32 51 | HANDLE h1,h2; 52 | #else 53 | int fd; 54 | #endif 55 | } MMAP; 56 | 57 | MMAP *mymmap (char *fname); 58 | int mymunmap (MMAP *m); 59 | 60 | }; 61 | #endif 62 | -------------------------------------------------------------------------------- /libcds/src/utils/BitString.cpp: -------------------------------------------------------------------------------- 1 | /* bitstring.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * bitstring definition 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | namespace cds_utils 26 | { 27 | 28 | BitString::BitString(ifstream & input) { 29 | assert(input.good()); 30 | input.read((char*)&length,sizeof(size_t)); 31 | input.read((char*)&uintLength,sizeof(size_t)); 32 | data = new uint[uintLength]; 33 | input.read((char*)data,uintLength*sizeof(uint)); 34 | } 35 | 36 | void BitString::initData(const size_t len) { 37 | length = len; 38 | uintLength = length/W+1; 39 | data = new uint[uintLength]; 40 | for(uint i=0;i fields, const size_t len) { 49 | initData(len); 50 | for(size_t i=0; i 3 | #include 4 | 5 | namespace cds_utils 6 | { 7 | 8 | uint transform(const string & s) { 9 | stringstream ss; 10 | ss << s; 11 | uint ret; 12 | ss >> ret; 13 | return ret; 14 | } 15 | 16 | }; 17 | -------------------------------------------------------------------------------- /libcds/src/utils/cppUtils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CPPUTILS 3 | #define _CPPUTILS 4 | 5 | #include 6 | #include 7 | 8 | namespace cds_utils 9 | { 10 | 11 | uint transform(const string & s); 12 | 13 | template void saveValue(ofstream & out, const T val) { 14 | assert(out.good()); 15 | out.write((char*)&val,sizeof(T)); 16 | } 17 | 18 | template T loadValue(ifstream & in) { 19 | assert(in.good()); 20 | T ret; 21 | in.read((char*)&ret,sizeof(T)); 22 | return ret; 23 | } 24 | 25 | template void saveValue(ofstream & out, const T * val, const size_t len) { 26 | assert(out.good()); 27 | out.write((char*)val,len*sizeof(T)); 28 | } 29 | 30 | template T * loadValue(ifstream & in, const size_t len) { 31 | assert(in.good()); 32 | T * ret = new T[len]; 33 | in.read((char*)ret,len*sizeof(T)); 34 | return ret; 35 | } 36 | 37 | template T * loadValue(const char * name, size_t & slen) { 38 | ifstream in(name); 39 | assert(in.good()); 40 | in.seekg(0,ios_base::end); 41 | size_t len = in.tellg(); 42 | slen = len/sizeof(T); 43 | if(len%sizeof(T)) slen--; 44 | in.seekg(0,ios_base::beg); 45 | T * ret = loadValue(in,slen); 46 | in.close(); 47 | return ret; 48 | } 49 | 50 | }; 51 | #endif 52 | -------------------------------------------------------------------------------- /libcds/tests/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CPP=g++ 3 | 4 | CPPFLAGS=-g3 -Wall -O0 -I../includes/ 5 | #CPPFLAGS=-O3 -Wall -DNDEBUG -I../includes/ 6 | LIB=../lib/libcds.a 7 | 8 | OBJECTS= testArray.o testBitSequence.o testSequence.o testHuffman.o testTextIndex.o testLCP.o testNPR.o testSuffixTree.o 9 | BIN= testArray testBitSequence testSequence testHuffman testTextIndex testLCP testNPR testSuffixTree 10 | 11 | %.o: %.cpp 12 | @echo " [C++] Compiling $<" 13 | @$(CPP) $(CPPFLAGS) -c $< -o $@ 14 | 15 | all: clean $(OBJECTS) $(BIN) 16 | @echo " [MSG] Done compiling tests" 17 | 18 | testHuffman: 19 | @echo " [LNK] Building testHuffman" 20 | @$(CPP) $(CPPFLAGS) -o testHuffman testHuffman.o $(LIB) 21 | 22 | testSequence: 23 | @echo " [LNK] Building testSequence" 24 | @$(CPP) $(CPPFLAGS) -o testSequence testSequence.o $(LIB) 25 | 26 | testBitSequence: 27 | @echo " [LNK] Building testBitSequence" 28 | @$(CPP) $(CPPFLAGS) -o testBitSequence testBitSequence.o $(LIB) 29 | 30 | testArray: 31 | @echo " [LNK] Building testArray" 32 | @$(CPP) $(CPPFLAGS) -o testArray testArray.o $(LIB) 33 | 34 | testTextIndex: 35 | @echo " [LNK] Building testTextIndex" 36 | @$(CPP) $(CPPFLAGS) -o testTextIndex testTextIndex.o $(LIB) 37 | 38 | testLCP: 39 | @echo " [LNK] Building testLCP" 40 | @$(CPP) $(CPPFLAGS) -o testLCP testLCP.o $(LIB) 41 | 42 | testNPR: 43 | @echo " [LNK] Building testNPR" 44 | @$(CPP) $(CPPFLAGS) -o testNPR testNPR.o $(LIB) 45 | 46 | testSuffixTree: 47 | @echo " [LNK] Building testSuffixTree" 48 | @$(CPP) $(CPPFLAGS) -o testSuffixTree testSuffixTree.o $(LIB) 49 | 50 | 51 | 52 | clean: 53 | @echo " [CLN] Cleaning object and binary files" 54 | @rm -f $(OBJECTS) $(BIN) 55 | -------------------------------------------------------------------------------- /libcds/tests/runTests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # runTests.py 4 | # Copyright (C) 2010, Francisco Claude, all rights reserved. 5 | # 6 | # Francisco Claude 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | # 21 | 22 | import sys,os,random,pickle,re 23 | 24 | 25 | print("******************************") 26 | print("Running tests for Array") 27 | res=os.system("./testArray") 28 | if res!=0: 29 | print("./testArray FAILED") 30 | 31 | 32 | -------------------------------------------------------------------------------- /libcds/tests/testHuffman.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | using namespace cds_utils; 9 | using namespace cds_static; 10 | 11 | 12 | int main(int argc, char ** argv) { 13 | 14 | if(argc!=4) { 15 | cout << "Checks the array class generating elements between 0 and using as seed for the numbers generation" << endl << endl; 16 | cout << "usage: " << argv[0] << " " << endl; 17 | return 0; 18 | } 19 | 20 | srand(transform(string(argv[1]))); 21 | uint len = transform(string(argv[2])); 22 | uint maxv = transform(string(argv[3])); 23 | 24 | //cout << "maxv = " << maxv << endl; 25 | //cout << "len = " << len << endl; 26 | 27 | Array a(len,maxv); 28 | for(uint i=0;imaxLength() << endl; 35 | 36 | for(size_t i=0;iencode(a[i],stream,ptr); 41 | for(size_t k=0;k 20 | 21 | using namespace std; 22 | using namespace cds_utils; 23 | using namespace cds_static; 24 | 25 | SuffixTree * saveLoad(SuffixTree * bs) { 26 | ofstream ofs("cst.tmp"); 27 | bs->save(ofs); 28 | ofs.close(); 29 | ifstream ifs("cst.tmp"); 30 | SuffixTree * ret = SuffixTree::load(ifs); 31 | ifs.close(); 32 | return ret; 33 | } 34 | 35 | bool testSuffixTree(SuffixTree *s1){ 36 | /*add any test you want*/ 37 | return true; 38 | } 39 | 40 | 41 | int main(int argc, char *argv[]){ 42 | char *text; 43 | size_t length; 44 | 45 | if(argc!=2) { 46 | cout << "Checks if the SuffixTree of the file is save/load correctly" << endl << endl; 47 | cout << "usage: " << argv[0] << " " << endl; 48 | return 0; 49 | } 50 | 51 | if(loadText(argv[1], &text, &length)) 52 | return 1; 53 | 54 | /*create index*/ 55 | 56 | SuffixTree *cst; 57 | 58 | SuffixTreeY csty(text, length, DAC, CN_NPR, 32); 59 | cst = saveLoad(&csty); 60 | if(!testSuffixTree(cst)) { 61 | cerr << "ERROR TESTING SuffixTreeY" << endl; 62 | return -1; 63 | } 64 | delete (SuffixTreeY *)cst; 65 | cout << "SuffixTree_Y OK\n" << endl; 66 | 67 | delete [] text; 68 | return 0; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /libcds/tests/testTextIndex.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | using namespace cds_utils; 9 | using namespace cds_static; 10 | 11 | TextIndex * saveLoad(TextIndex * bs) { 12 | ofstream ofs("textindex.tmp"); 13 | bs->save(ofs); 14 | ofs.close(); 15 | ifstream ifs("textindex.tmp"); 16 | TextIndex * ret = TextIndex::load(ifs); 17 | ifs.close(); 18 | return ret; 19 | } 20 | 21 | bool testTextIndex(TextIndex *s1, TextIndex *s2){ 22 | for(size_t i=0; iindex_length(); i++){ 23 | if(s1->getSA(i)!=s2->getSA(i)) 24 | return false; 25 | if(s1->getISA(i)!=s2->getISA(i)) 26 | return false; 27 | if(s1->getPsi(i)!=s2->getPsi(i)) 28 | return false; 29 | } 30 | return true; 31 | } 32 | 33 | int main(int argc, char ** argv) { 34 | 35 | if(argc!=2) { 36 | cout << "Checks if the TextIndex of the file is save/load correctly" << endl << endl; 37 | cout << "usage: " << argv[0] << " " << endl; 38 | return 0; 39 | } 40 | char *text=NULL; 41 | size_t length; 42 | TextIndex *ticsa, *load_ticsa; 43 | 44 | if(loadText(argv[1], &text, &length)) 45 | return 1; 46 | cout << "length: " << length << endl; 47 | 48 | ticsa = new TextIndexCSA((uchar *)text, (ulong)length, NULL); 49 | 50 | load_ticsa = saveLoad(ticsa); 51 | 52 | if(!testTextIndex(ticsa, load_ticsa)) { 53 | cerr << "ERROR TESTING TextIndexCSA" << endl; 54 | return -1; 55 | } 56 | 57 | cout << "CSA OK\n" << endl; 58 | delete (TextIndexCSA *)ticsa; 59 | delete (TextIndexCSA *)load_ticsa; 60 | if(text!=NULL) 61 | delete text; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /utils/Coder/BinaryNode.cpp: -------------------------------------------------------------------------------- 1 | /* BinaryNode.cpp 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * This class models the binary nodes used for building statiscal codes. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 | * Contacting the authors: 23 | * Francisco Claude: fclaude@recoded.cl 24 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 25 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 26 | */ 27 | 28 | 29 | #include "BinaryNode.h" 30 | 31 | BinaryNode::BinaryNode() 32 | { 33 | this->type = 0; 34 | this->position = -1; 35 | this->weight = -1; 36 | 37 | this->leftChild = this->rightChild = NULL; 38 | } 39 | 40 | BinaryNode::BinaryNode(uint type, uint position, uint weight) 41 | { 42 | this->type = type; 43 | this->position = position; 44 | this->weight = weight; 45 | 46 | this->leftChild = this->rightChild = NULL; 47 | } 48 | 49 | BinaryNode::~BinaryNode() 50 | { 51 | } 52 | 53 | -------------------------------------------------------------------------------- /utils/Coder/BinaryNode.h: -------------------------------------------------------------------------------- 1 | /* BinaryNode.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * This class models the binary nodes used for building statiscal codes. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 | * Contacting the authors: 23 | * Francisco Claude: fclaude@recoded.cl 24 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 25 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 26 | */ 27 | 28 | 29 | #ifndef _BINARYNODE_H 30 | #define _BINARYNODE_H 31 | 32 | #include 33 | using namespace std; 34 | 35 | #include 36 | using namespace cds_utils; 37 | 38 | class BinaryNode 39 | { 40 | public: 41 | /** Generic Constructor */ 42 | BinaryNode(); 43 | 44 | /** Class Constructor. 45 | @param type: describes the node type (0=external / 1=internal). 46 | @param position: points to the node position in the global 47 | sequence. 48 | @param weight: node weight (frequency). 49 | */ 50 | BinaryNode(uint type, uint position, uint weight); 51 | 52 | /** Generic Destructor */ 53 | ~BinaryNode(); 54 | 55 | protected: 56 | bool type; // Node type 57 | int position; // Node position 58 | int weight; // Node weight 59 | 60 | BinaryNode *leftChild; // Pointer to the (possible) left child 61 | BinaryNode *rightChild; // Pointer to the (possible) right child 62 | 63 | friend class HuTucker; 64 | friend class Huffman; 65 | }; 66 | 67 | 68 | 69 | 70 | 71 | #endif /* _BINARYNODE_H */ 72 | 73 | -------------------------------------------------------------------------------- /utils/Coder/Codeword.h: -------------------------------------------------------------------------------- 1 | /* Codeword.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * Simple bit-based codeword. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * 22 | * Contacting the authors: 23 | * Francisco Claude: fclaude@recoded.cl 24 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 25 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 26 | */ 27 | 28 | 29 | #ifndef _CODEWORD_H 30 | #define _CODEWORD_H 31 | 32 | class Codeword 33 | { 34 | public: 35 | /** Generic Constructor */ 36 | Codeword() { this->codeword = 0; this->bits = 0; } 37 | 38 | /** Class Constructor. 39 | @param codeword: the codeword 40 | @param bits: the codeword length (in bits) 41 | */ 42 | Codeword(uint codeword, uint bits) 43 | { 44 | this->codeword = codeword; 45 | this->bits = bits; 46 | } 47 | 48 | /** Generic Destructor */ 49 | ~Codeword() {}; 50 | 51 | protected: 52 | uint codeword; // Codeword (right-aligned) 53 | uint bits; // Codeword length in number of bits 54 | 55 | friend class StatCoder; 56 | friend class DecodingTableBuilder; 57 | 58 | friend class HuTucker; 59 | friend class Huffman; 60 | 61 | friend class StringDictionaryHASHHF; 62 | friend class StringDictionaryHASHUFFDAC; 63 | friend class StringDictionaryHTFC; 64 | friend class StringDictionaryHHTFC; 65 | friend class StringDictionaryRPHTFC; 66 | 67 | friend class IteratorDictStringHTFC; 68 | friend class IteratorDictStringHHTFC; 69 | friend class IteratorDictStringRPHTFC; 70 | }; 71 | 72 | 73 | #endif /* _CODEWORD_H */ 74 | 75 | -------------------------------------------------------------------------------- /utils/VByte.cpp: -------------------------------------------------------------------------------- 1 | /* VByte.cpp 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * This class implements the Variable Byte (VByte) Code: 6 | * 7 | * ========================================================================== 8 | * "Compressing integers for fast file access" 9 | * Hugh Williams and Justin Zobel. 10 | * The Computer Journal 42, p.193-201, 1999. 11 | * ========================================================================== 12 | * 13 | * This library is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU Lesser General Public 15 | * License as published by the Free Software Foundation; either 16 | * version 2.1 of the License, or (at your option) any later version. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this library; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | * 27 | * 28 | * Contacting the authors: 29 | * Francisco Claude: fclaude@recoded.cl 30 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 31 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 32 | */ 33 | 34 | 35 | 36 | #include "VByte.h" 37 | 38 | uint 39 | VByte::encode(uint c, uchar *r) 40 | { 41 | unsigned int i= 0; 42 | 43 | while (c>127) 44 | { 45 | r[i] = (unsigned char)(c&127); 46 | i++; 47 | c>>=7; 48 | } 49 | 50 | r[i] = (unsigned char)(c|0x80); 51 | i++; 52 | 53 | return i; 54 | } 55 | 56 | uint 57 | VByte::decode(uint *c, uchar *r) 58 | { 59 | *c = 0; 60 | register int i = 0; 61 | register int shift = 0; 62 | 63 | while ( !(r[i] & 0x80) ) 64 | { 65 | *c |= (r[i] & 127) << shift; 66 | i++; 67 | shift+=7; 68 | } 69 | 70 | *c |= (r[i] & 127) << shift; 71 | i++; 72 | 73 | return i; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /utils/VByte.h: -------------------------------------------------------------------------------- 1 | /* VByte.h 2 | * Copyright (C) 2014, Francisco Claude & Rodrigo Canovas & Miguel A. Martinez-Prieto 3 | * all rights reserved. 4 | * 5 | * This class implements the Variable Byte (VByte) Code: 6 | * 7 | * ========================================================================== 8 | * "Compressing integers for fast file access" 9 | * Hugh Williams and Justin Zobel. 10 | * The Computer Journal 42, p.193-201, 1999. 11 | * ========================================================================== 12 | * 13 | * This library is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU Lesser General Public 15 | * License as published by the Free Software Foundation; either 16 | * version 2.1 of the License, or (at your option) any later version. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this library; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | * 27 | * 28 | * Contacting the authors: 29 | * Francisco Claude: fclaude@recoded.cl 30 | * Rodrigo Canovas: rcanovas@student.unimelb.edu.au 31 | * Miguel A. Martinez-Prieto: migumar2@infor.uva.es 32 | */ 33 | 34 | 35 | #ifndef _VBYTE_H 36 | #define _VBYTE_H 37 | 38 | #include 39 | using namespace std; 40 | 41 | #include 42 | using namespace cds_utils; 43 | 44 | class VByte 45 | { 46 | public: 47 | /** Encodes the integer 'c' in the sequence of bytes (uchar) 'r'. 48 | @param c: the number to be encoded. 49 | @param r: the resulting encoded sequence. 50 | @returns the number of bytes used for encoding. 51 | */ 52 | static uint encode(uint c, uchar *r); 53 | 54 | /** Decodes the sequence of bytes (uchar) 'r' into the integer 'c'. 55 | @param c: the resulting decoded number. 56 | @param r: the sequence to be decoded. 57 | @returns the number of bytes read for decoding. 58 | */ 59 | static uint decode(uint *c, uchar *r); 60 | }; 61 | 62 | #endif /* _VBYTE_H */ 63 | 64 | --------------------------------------------------------------------------------