├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── Changelog ├── Doxyfile ├── INSTALL ├── Makefile.am ├── Makefile.in ├── NEWS ├── README ├── aclocal.m4 ├── build-aux ├── config.guess ├── config.h.in ├── config.sub ├── depcomp ├── install-sh ├── ltmain.sh └── missing ├── cds.pc.in ├── configure ├── configure.ac ├── include ├── Array.h ├── BitSequence.h ├── BitSequenceBuilder.h ├── BitSequenceBuilderDArray.h ├── BitSequenceBuilderRG.h ├── BitSequenceBuilderRRR.h ├── BitSequenceBuilderSDArray.h ├── BitSequenceDArray.h ├── BitSequenceRG.h ├── BitSequenceRRR.h ├── BitSequenceSDArray.h ├── BitmapsSequence.h ├── Coder.h ├── HuffmanCoder.h ├── Mapper.h ├── MapperCont.h ├── MapperNone.h ├── MapperRev.h ├── Permutation.h ├── PermutationBuilder.h ├── PermutationBuilderMRRR.h ├── PermutationBuilderWT.h ├── PermutationMRRR.h ├── PermutationWT.h ├── Sequence.h ├── SequenceAlphPart.h ├── SequenceBuilder.h ├── SequenceBuilderAlphPart.h ├── SequenceBuilderGMR.h ├── SequenceBuilderGMRChunk.h ├── SequenceBuilderStr.h ├── SequenceBuilderWaveletMatrix.h ├── SequenceBuilderWaveletTree.h ├── SequenceBuilderWaveletTreeNoptrs.h ├── SequenceBuilderWaveletTreeNoptrsS.h ├── SequenceGMR.h ├── SequenceGMRChunk.h ├── TableOffsetRRR.h ├── WaveletMatrix.h ├── WaveletTree.h ├── WaveletTreeNoptrs.h ├── WaveletTreeNoptrsS.h ├── cppUtils.h ├── huff.h ├── libcdsBasics.h ├── libcdsBitString.h ├── libcdsSDArray.h ├── libcdsTrees.h ├── perm.h ├── sdarraySadakane.h ├── timing.h ├── wt_coder.h ├── wt_coder_binary.h ├── wt_coder_huff.h ├── wt_node.h ├── wt_node_internal.h └── wt_node_leaf.h ├── m4 ├── ax_prog_doxygen.m4 ├── libtool.m4 ├── ltoptions.m4 ├── ltsugar.m4 ├── ltversion.m4 └── lt~obsolete.m4 ├── src ├── Makefile.am ├── Makefile.in ├── static │ ├── bitsequence │ │ ├── BitSequence.cpp │ │ ├── BitSequenceBuilderDArray.cpp │ │ ├── BitSequenceBuilderRG.cpp │ │ ├── BitSequenceBuilderRRR.cpp │ │ ├── BitSequenceBuilderSDArray.cpp │ │ ├── BitSequenceDArray.cpp │ │ ├── BitSequenceRG.cpp │ │ ├── BitSequenceRRR.cpp │ │ ├── BitSequenceSDArray.cpp │ │ ├── TableOffsetRRR.cpp │ │ └── sdarraySadakane.cpp │ ├── coders │ │ ├── HuffmanCoder.cpp │ │ └── huff.cpp │ ├── mapper │ │ ├── Mapper.cpp │ │ ├── MapperCont.cpp │ │ ├── MapperNone.cpp │ │ └── MapperRev.cpp │ ├── permutation │ │ ├── Permutation.cpp │ │ ├── PermutationBuilderMRRR.cpp │ │ ├── PermutationBuilderWT.cpp │ │ ├── PermutationMRRR.cpp │ │ ├── PermutationWT.cpp │ │ └── perm.cpp │ └── sequence │ │ ├── BitmapsSequence.cpp │ │ ├── Sequence.cpp │ │ ├── SequenceAlphPart.cpp │ │ ├── SequenceBuilderAlphPart.cpp │ │ ├── SequenceBuilderGMR.cpp │ │ ├── SequenceBuilderGMRChunk.cpp │ │ ├── SequenceBuilderStr.cpp │ │ ├── SequenceBuilderWaveletMatrix.cpp │ │ ├── SequenceBuilderWaveletTree.cpp │ │ ├── SequenceBuilderWaveletTreeNoptrs.cpp │ │ ├── SequenceBuilderWaveletTreeNoptrsS.cpp │ │ ├── SequenceGMR.cpp │ │ ├── SequenceGMRChunk.cpp │ │ ├── WaveletMatrix.cpp │ │ ├── WaveletTree.cpp │ │ ├── WaveletTreeNoptrs.cpp │ │ ├── WaveletTreeNoptrsS.cpp │ │ ├── wt_coder.cpp │ │ ├── wt_coder_binary.cpp │ │ ├── wt_coder_huff.cpp │ │ ├── wt_node.cpp │ │ ├── wt_node_internal.cpp │ │ └── wt_node_leaf.cpp └── utils │ ├── Array.cpp │ ├── cppUtils.cpp │ ├── libcdsBitString.cpp │ └── timing.cpp ├── tests ├── Makefile.am ├── Makefile.in ├── testArray.cpp ├── testBitSequence.cpp ├── testHuffman.cpp ├── testQuantile.cpp ├── testSequence.cpp ├── timeSequence.cpp ├── toArray.cpp └── toArray2.cpp └── tutorial ├── src ├── ArrayExample.cpp ├── ArrayExample2.cpp ├── BitSequenceRGExample.cpp ├── BitSequenceRRRExample.cpp ├── BitSequenceSDArrayExample.cpp ├── Makefile.am ├── Makefile.in ├── SequenceAlphPartExample.cpp ├── SequenceGMRExample.cpp └── SequenceWaveletTreeExample.cpp ├── ssa ├── Makefile.am ├── Makefile.in ├── build_index.cpp ├── dump_bwt.cpp ├── ssa.cpp ├── ssa.h └── test_count.cpp └── tutorial.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | *~ 3 | *.o 4 | *.lo 5 | *.a 6 | *.so 7 | *.exe 8 | .DS_Store 9 | cds.pc 10 | # configure cruft 11 | .deps/ 12 | .dirstamp 13 | .libs/ 14 | autom4te.cache/ 15 | Makefile 16 | build-aux/config.h 17 | build-aux/stamp-h1 18 | config.log 19 | config.status 20 | libtool 21 | src/Makefile 22 | src/libcds.la 23 | tests/Makefile 24 | tutorial/src/Makefile 25 | tutorial/ssa/Makefile 26 | tutorial/src/ArrayExample 27 | tutorial/src/ArrayExample2 28 | tutorial/src/BitSequenceRGExample 29 | tutorial/src/BitSequenceRRRExample 30 | tutorial/src/BitSequenceSDArrayExample 31 | tutorial/src/SequenceAlphPartExample 32 | tutorial/src/SequenceGMRExample 33 | tutorial/src/SequenceWaveletTreeExample 34 | tutorial/ssa/build_index 35 | tutorial/ssa/dump_bwt 36 | tutorial/ssa/test_count 37 | tests/bitsequence.tmp 38 | tests/testArray 39 | tests/testBitSequence 40 | tests/testHuffman 41 | tests/testQuantile 42 | tests/testSequence 43 | tests/timeSequence 44 | tests/toArray 45 | tests/toArray2 46 | /docs/html/ 47 | /docs/latex/ 48 | /docs/cds.ps 49 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fclaude/libcds/c3002bef485ac00ed42e544c1aa2699b4d8c9311/AUTHORS -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fclaude/libcds/c3002bef485ac00ed42e544c1aa2699b4d8c9311/ChangeLog -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fclaude/libcds/c3002bef485ac00ed42e544c1aa2699b4d8c9311/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | libcds implements low-level succinct data structures such as bitmaps, 2 | sequences, permutations, etc. The main goal is to provide a set of 3 | structures that form the building block of most compressed/succinct 4 | solutions. In the near future we are planning to add compression 5 | algorithms and support for succinct trees. 6 | 7 | You can find more information at http://libcds.recoded.cl/ 8 | 9 | Right now we are just fixing bugs and testing some new things in here, 10 | but most of the effort is being put into libcds2, this rewrite aims at 11 | solving many problems with 64bits systems. This is necessary in order 12 | to index bigger inputs. 13 | 14 | BUILD INSTRUCTIONS 15 | 16 | To do a normal build for your platform, just do: 17 | 18 | ./configure && make && make check 19 | 20 | To install "make install". If you want the library installed elsewhere, 21 | run the configure script at the beginning with a --prefix flag 22 | ("./configure --prefix=/usr/local"). Run ./configure --help for more 23 | information on the build configuration script and refer to the INSTALL 24 | file for more information. 25 | 26 | BUILDING DOCUMENTATION 27 | 28 | Documentation is provided by doxygen. This can be built by running: 29 | 30 | make doxygen-doc 31 | 32 | You'll need the doxygen tools to build these docs however. On an Ubuntu 33 | machine do the following to install all the required packages. 34 | 35 | sudo apt-get install doxygen texlive-fonts-recommended texlive-fonts-extra 36 | 37 | CROSS BUILD INSTRUCTIONS 38 | 39 | To build for a windows target on an Ubuntu system you can use the mingw32 40 | cross compiler: 41 | 42 | sudo apt-get install g++-mingw-w64 43 | ./configure --host=i686-w64-mingw32 44 | make 45 | -------------------------------------------------------------------------------- /build-aux/config.h.in: -------------------------------------------------------------------------------- 1 | /* build-aux/config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_DLFCN_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_INTTYPES_H 8 | 9 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 10 | to 0 otherwise. */ 11 | #undef HAVE_MALLOC 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #undef HAVE_MEMORY_H 15 | 16 | /* Define to 1 if your system has a GNU libc compatible `realloc' function, 17 | and to 0 otherwise. */ 18 | #undef HAVE_REALLOC 19 | 20 | /* Define to 1 if you have the `select' function. */ 21 | #undef HAVE_SELECT 22 | 23 | /* Define to 1 if stdbool.h conforms to C99. */ 24 | #undef HAVE_STDBOOL_H 25 | 26 | /* Define to 1 if you have the header file. */ 27 | #undef HAVE_STDINT_H 28 | 29 | /* Define to 1 if you have the header file. */ 30 | #undef HAVE_STDLIB_H 31 | 32 | /* Define to 1 if you have the header file. */ 33 | #undef HAVE_STRINGS_H 34 | 35 | /* Define to 1 if you have the header file. */ 36 | #undef HAVE_STRING_H 37 | 38 | /* Define to 1 if you have the header file. */ 39 | #undef HAVE_SYS_STAT_H 40 | 41 | /* Define to 1 if you have the header file. */ 42 | #undef HAVE_SYS_TIMEB_H 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #undef HAVE_SYS_TYPES_H 46 | 47 | /* Define to 1 if you have the header file. */ 48 | #undef HAVE_UNISTD_H 49 | 50 | /* Define to 1 if the system has the type `_Bool'. */ 51 | #undef HAVE__BOOL 52 | 53 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 54 | */ 55 | #undef LT_OBJDIR 56 | 57 | /* Name of package */ 58 | #undef PACKAGE 59 | 60 | /* Define to the address where bug reports for this package should be sent. */ 61 | #undef PACKAGE_BUGREPORT 62 | 63 | /* Define to the full name of this package. */ 64 | #undef PACKAGE_NAME 65 | 66 | /* Define to the full name and version of this package. */ 67 | #undef PACKAGE_STRING 68 | 69 | /* Define to the one symbol short name of this package. */ 70 | #undef PACKAGE_TARNAME 71 | 72 | /* Define to the home page for this package. */ 73 | #undef PACKAGE_URL 74 | 75 | /* Define to the version of this package. */ 76 | #undef PACKAGE_VERSION 77 | 78 | /* Define to 1 if you have the ANSI C header files. */ 79 | #undef STDC_HEADERS 80 | 81 | /* Version number of package */ 82 | #undef VERSION 83 | 84 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 85 | , or is not used. If the typedef were allowed, the 86 | #define below would cause a syntax error. */ 87 | #undef _UINT32_T 88 | 89 | /* Define to `__inline__' or `__inline' if that's what the C compiler 90 | calls it, or to nothing if 'inline' is not supported under any name. */ 91 | #ifndef __cplusplus 92 | #undef inline 93 | #endif 94 | 95 | /* Define to rpl_malloc if the replacement function should be used. */ 96 | #undef malloc 97 | 98 | /* Define to rpl_realloc if the replacement function should be used. */ 99 | #undef realloc 100 | 101 | /* Define to `unsigned int' if does not define. */ 102 | #undef size_t 103 | 104 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 105 | such a type exists and the standard includes do not define it. */ 106 | #undef uint32_t 107 | -------------------------------------------------------------------------------- /cds.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: @PACKAGE_NAME@ 7 | Description: C++ Compact Data Structures Library 8 | Version: @PACKAGE_VERSION@ 9 | URL: @PACKAGE_URL@ 10 | Libs: -L${libdir} -lcds 11 | Cflags: -I${includedir}/libcds -I${libdir}/libcds/include 12 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # To rebuild the configure script and Makefile.in files (as well as some 3 | # supporting files mainly in build-aux/ and m4/) run the following 4 | # command: 5 | # autoreconf -vif 6 | 7 | AC_PREREQ([2.68]) 8 | AC_INIT([libcds], [1.0], [fclaude@gmail.com], [cds], 9 | [https://github.com/fclaude/libcds]) 10 | AC_CONFIG_SRCDIR([src/static/bitsequence/BitSequenceBuilderDArray.cpp]) 11 | AC_CONFIG_MACRO_DIR([m4]) 12 | AC_CONFIG_AUX_DIR([build-aux]) 13 | AC_CONFIG_HEADERS([build-aux/config.h]) 14 | AM_INIT_AUTOMAKE([1.11 subdir-objects]) 15 | AM_SILENT_RULES([yes]) 16 | LT_INIT([shared static]) 17 | AC_SUBST([LIBTOOL_DEPS]) 18 | AC_SUBST([CDS_SO_VERSION], [1:3:0]) 19 | DX_INIT_DOXYGEN([libcds], [Doxyfile], [docs/]) 20 | 21 | # Checks for programs. 22 | AC_PROG_CXX 23 | AC_LANG([C++]) 24 | AC_PROG_INSTALL 25 | AC_PROG_MAKE_SET 26 | 27 | # Checks for libraries. 28 | 29 | # Checks for header files. 30 | AC_CHECK_HEADERS([stdint.h stdlib.h sys/timeb.h unistd.h]) 31 | 32 | # Checks for typedefs, structures, and compiler characteristics. 33 | AC_HEADER_STDBOOL 34 | AC_C_INLINE 35 | AC_TYPE_SIZE_T 36 | AC_TYPE_UINT32_T 37 | 38 | # Checks for library functions. 39 | AC_FUNC_MALLOC 40 | AC_FUNC_REALLOC 41 | AC_CHECK_FUNCS([select]) 42 | 43 | AC_CONFIG_FILES([Makefile 44 | cds.pc 45 | src/Makefile 46 | tests/Makefile 47 | tutorial/src/Makefile 48 | tutorial/ssa/Makefile]) 49 | AC_OUTPUT 50 | -------------------------------------------------------------------------------- /include/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 | virtual ~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 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/BitSequenceDArray.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 _BITSEQUENCEDARRAY_H 26 | #define _BITSEQUENCEDARRAY_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace cds_utils; 34 | 35 | namespace cds_static 36 | { 37 | class BitSequenceDArray: public BitSequence 38 | { 39 | 40 | public: 41 | /** Builds the DArray (Sadakane's dense version for rank/select*/ 42 | BitSequenceDArray(const BitString & bs); 43 | /** Builds the DArray */ 44 | BitSequenceDArray(uint * buff, size_t len); 45 | virtual ~BitSequenceDArray(); 46 | virtual size_t select1(size_t i) const; 47 | virtual size_t rank0(size_t i) const; 48 | virtual size_t rank1(size_t i) const; 49 | virtual size_t getSize() const; 50 | virtual void save(ofstream & fp) const; 51 | static BitSequenceDArray * load(ifstream & fp); 52 | 53 | protected: 54 | uint m; //number of 1's 55 | uint nl, s_ss, s_sl; 56 | uint *a; //bitarray 57 | uint *lp; 58 | uint *sl; 59 | uint *ss; 60 | uint *p; 61 | uint *rl; 62 | uchar *rs; 63 | 64 | /** Internal building function, same parameters as the base constructor. */ 65 | void build(uint *buff, size_t len); 66 | 67 | /** Protected constructor for loaders, you have to initialize data before 68 | *using an object built with this constructor. 69 | */ 70 | BitSequenceDArray(); 71 | 72 | }; 73 | }; 74 | #endif 75 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/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, bool keepsSequence); 45 | BitmapsSequence(const Array & a, Mapper * am, BitSequenceBuilder * bsb, bool keepsSequence); 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 | bool keepsSequence; 68 | Array *seq; 69 | 70 | BitmapsSequence(); 71 | 72 | }; 73 | 74 | }; 75 | #endif /* _BITMAPSSEQUENCE_H */ 76 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/HuffmanCoder.h: -------------------------------------------------------------------------------- 1 | /* HuffmanCoder.h 2 | Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | 4 | Wrapper for huff written by Gonzalo Navarro 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 HUFFMAN_CODES_H 23 | #define HUFFMAN_CODES_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace cds_utils; 31 | namespace cds_static 32 | { 33 | 34 | #define HUFF_HDR 1 35 | 36 | /** Wrapper for the canonical huffman implementation of Gonzalo Navarro. 37 | * 38 | * @author Francisco Claude 39 | */ 40 | class HuffmanCoder : public Coder 41 | { 42 | 43 | public: 44 | /** Creates the codes for the sequence seq of length n */ 45 | HuffmanCoder(uint * seq, size_t n); 46 | HuffmanCoder(uchar * seq, size_t n); 47 | HuffmanCoder(Array & seq); 48 | 49 | virtual ~HuffmanCoder(); 50 | 51 | /** Encodes symb into stream at bit-position pos, 52 | * returns the ending position (bits) */ 53 | virtual size_t encode(uint symb, uint * stream, size_t pos) const; 54 | 55 | /** decodes into symb from stream at bit-position 56 | * pos, returns the new position */ 57 | virtual size_t decode(uint * symb, uint * stream, size_t pos) const; 58 | 59 | /** Returns the maximum length of a code */ 60 | virtual size_t maxLength() const; 61 | 62 | /** Returns the size of the table */ 63 | virtual size_t getSize() const; 64 | 65 | /** Saves the coder to a file */ 66 | virtual void save(ofstream & fp) const; 67 | 68 | /** Loads a coder from a file */ 69 | static HuffmanCoder * load(ifstream & fp); 70 | 71 | protected: 72 | HuffmanCoder(); 73 | THuff huff_table; 74 | }; 75 | 76 | }; 77 | #endif 78 | -------------------------------------------------------------------------------- /include/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 | #define MAPPER_REV_HDR 4 36 | 37 | /** Base class for alphabet mappers 38 | * 39 | * @author Francisco Claude 40 | */ 41 | class Mapper 42 | { 43 | public: 44 | Mapper(); 45 | virtual ~Mapper() {} 46 | /** Maps the symbol */ 47 | virtual uint map(uint s) const=0; 48 | /** Unmaps the symbol */ 49 | virtual uint unmap(uint s) const=0; 50 | /** Returns the size of the mapper */ 51 | virtual size_t getSize() const=0; 52 | /** Saves the mapper to a file */ 53 | virtual void save(ofstream & out) const=0; 54 | /** Loads the mapper from a file */ 55 | static Mapper * load(ifstream & input); 56 | /** Reference counter incrementor */ 57 | virtual void use(); 58 | /** Reference counter decrementor */ 59 | virtual void unuse(); 60 | 61 | protected: 62 | /** Nr of references */ 63 | int userCount; 64 | }; 65 | }; 66 | 67 | #include 68 | #include 69 | #include 70 | #endif /* _MAPPER_H */ 71 | -------------------------------------------------------------------------------- /include/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 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace std; 35 | using namespace cds_utils; 36 | 37 | namespace cds_static 38 | { 39 | 40 | /** Mapper that makes the values in the set contiguous 41 | * 42 | * @author Francisco Claude 43 | */ 44 | class MapperCont : public Mapper 45 | { 46 | public: 47 | MapperCont(const Array & seq, const BitSequenceBuilder & bsb); 48 | MapperCont(const uint * A, const size_t len, const BitSequenceBuilder & bsb); 49 | 50 | virtual ~MapperCont(); 51 | 52 | virtual uint map(uint s) const; 53 | virtual uint unmap(uint s) const; 54 | virtual size_t getSize() const; 55 | 56 | virtual void save(ofstream & out) const; 57 | static MapperCont * load(ifstream & input); 58 | 59 | protected: 60 | MapperCont(); 61 | BitSequence * m; 62 | }; 63 | 64 | }; 65 | #endif /* _MAPPERCONT_H */ 66 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/MapperRev.h: -------------------------------------------------------------------------------- 1 | /* MapperRev.h 2 | * Copyright (C) 2012, Francisco Claude, all rights reserved. 3 | * 4 | * MapperRev 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 _MAPPERREV_H 23 | #define _MAPPERREV_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 reverses the bits (considering how many bits are required 40 | * to represent the maximum value in the sequence) 41 | * 42 | * @author Francisco Claude 43 | */ 44 | class MapperRev : public Mapper 45 | { 46 | public: 47 | MapperRev(const Array &a); 48 | MapperRev(const uint *A, const size_t len); 49 | virtual ~MapperRev() {} 50 | virtual uint map(const uint s) const; 51 | virtual uint unmap(const uint s) const; 52 | virtual size_t getSize() const; 53 | virtual void save(ofstream & out) const; 54 | static MapperRev * load(ifstream & input); 55 | 56 | protected: 57 | MapperRev(); 58 | uint bits; 59 | }; 60 | }; 61 | #endif /* __MAPPER_REV_H */ 62 | -------------------------------------------------------------------------------- /include/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 | { 30 | class Permutation 31 | { 32 | public: 33 | Permutation(); 34 | virtual ~Permutation(); 35 | 36 | /** Compute the value at position i 37 | */ 38 | virtual uint pi(uint i) const; 39 | 40 | /** Compute the position where i appears */ 41 | virtual uint revpi(uint i) const; 42 | 43 | /** Compose pi k times. 44 | */ 45 | virtual uint pi(uint i, uint k) const; 46 | 47 | /** Compose revpi k times 48 | */ 49 | virtual uint revpi(uint i, uint k) const; 50 | 51 | /** retrieves the length of the permutation 52 | */ 53 | virtual size_t getLength() const; 54 | 55 | /** Size in bytes 56 | */ 57 | virtual size_t getSize() const = 0; 58 | 59 | /** Saves permutation to stream */ 60 | virtual void save(ofstream & fp) const; 61 | 62 | /** Loads the permutation */ 63 | static Permutation * load(ifstream & fp); 64 | 65 | protected: 66 | size_t length; 67 | }; 68 | }; 69 | 70 | #define MRRRPERM 1 71 | #define WTPERM 2 72 | 73 | #include 74 | #include 75 | #endif 76 | -------------------------------------------------------------------------------- /include/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 | 30 | class PermutationBuilder 31 | { 32 | public: 33 | PermutationBuilder() { userCount=0; } 34 | virtual ~PermutationBuilder() {} 35 | virtual Permutation * build(uint * perm, uint n) const = 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 | #endif 47 | -------------------------------------------------------------------------------- /include/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 | 31 | class PermutationBuilderMRRR : public PermutationBuilder 32 | { 33 | public: 34 | PermutationBuilderMRRR(uint sample, BitSequenceBuilder * bmb); 35 | virtual ~PermutationBuilderMRRR(); 36 | virtual Permutation * build(uint * perm, uint len) const; 37 | protected: 38 | uint sample; 39 | BitSequenceBuilder * bmb; 40 | }; 41 | }; 42 | #endif 43 | -------------------------------------------------------------------------------- /include/PermutationBuilderWT.h: -------------------------------------------------------------------------------- 1 | /* PermutationBuilderWT.h 2 | * Copyright (C) 2011, 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 PERMUTATIONBUILDERWT_H 22 | #define PERMUTATIONBUILDERWT_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace cds_static 29 | { 30 | 31 | class PermutationBuilderWT : public PermutationBuilder 32 | { 33 | public: 34 | PermutationBuilderWT() {} 35 | virtual ~PermutationBuilderWT() {} 36 | virtual Permutation * build(uint * perm, uint len) const; 37 | }; 38 | }; 39 | #endif 40 | -------------------------------------------------------------------------------- /include/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 | 34 | /** Wrapper for Diego Arroyuelo's implementation of Munro et al.'s permutations. 35 | * @author Francisco Claude 36 | */ 37 | class PermutationMRRR : public Permutation 38 | { 39 | public: 40 | PermutationMRRR(uint * elems, uint nelems, uint t, BitSequenceBuilder * bmb); 41 | virtual ~PermutationMRRR(); 42 | /** Computes the i-th element of the permutation */ 43 | virtual uint pi(uint i) const; 44 | /** Computes the inverse of i */ 45 | virtual uint revpi(uint i) const; 46 | /** Saves the permutation to fp, returns 0 in case of success */ 47 | virtual void save(ofstream & fp) const; 48 | /** Returns the size of the permutation */ 49 | virtual size_t getSize() const; 50 | /** Loads a static_permutation from fp */ 51 | static PermutationMRRR * load(ifstream & fp); 52 | protected: 53 | perm permutation; 54 | PermutationMRRR(); 55 | }; 56 | 57 | }; 58 | #endif 59 | -------------------------------------------------------------------------------- /include/PermutationWT.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 | #ifndef __PERMUTATIONWT_H 22 | #define __PERMUTATIONWT_H 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace cds_utils; 31 | 32 | namespace cds_static 33 | { 34 | class WaveletTree; 35 | 36 | class PermutationWT:public Permutation 37 | { 38 | public: 39 | PermutationWT(uint * perm, size_t len); 40 | virtual ~PermutationWT(); 41 | 42 | /** Compute the value at position i 43 | */ 44 | virtual uint pi(uint i) const; 45 | 46 | /** Compute the position where i appears */ 47 | virtual uint revpi(uint i) const; 48 | 49 | /** Size in bytes 50 | */ 51 | virtual size_t getSize() const; 52 | 53 | /** Saves permutation to stream */ 54 | virtual void save(ofstream & fp) const; 55 | 56 | /** Loads the permutation */ 57 | static PermutationWT * load(ifstream & fp); 58 | 59 | protected: 60 | PermutationWT() {} 61 | BitSequence * marks; 62 | Sequence * wt; 63 | uint runs; 64 | }; 65 | }; 66 | #endif 67 | -------------------------------------------------------------------------------- /include/Sequence.h: -------------------------------------------------------------------------------- 1 | /* Sequence.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * 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 _SEQUENCE_H 23 | #define _SEQUENCE_H 24 | 25 | #include 26 | #include 27 | 28 | using namespace cds_utils; 29 | using namespace std; 30 | 31 | namespace cds_static 32 | { 33 | 34 | #define BS_HDR 1 35 | #define WVTREE_HDR 2 36 | #define WVTREE_NOPTRS_HDR 3 37 | #define GMR_HDR 4 38 | #define GMR_CHUNK_HDR 5 39 | #define ALPHPART_HDR 6 40 | #define WVMATRIX_HDR 7 41 | #define WVTREE_NOPTRSS_HDR 8 42 | 43 | /** Sequence base class 44 | * 45 | * @author Francisco Claude 46 | */ 47 | class Sequence 48 | { 49 | 50 | public: 51 | /** Builds and sets the length */ 52 | Sequence(size_t length); 53 | virtual ~Sequence() {} 54 | 55 | /** Count the number of occurrences of c up to position i included 56 | */ 57 | virtual size_t rank(uint c, size_t i) const; 58 | 59 | /** Retrieve the i-th position where c appears. 60 | * It returns (size_t)-1 if i=0 and length if the number of 61 | * c's is less than i 62 | */ 63 | virtual size_t select(uint c, size_t i) const; 64 | 65 | /** Retrieves the next occurrence of a c starting at position i (included). 66 | * It return length if there are no occurrences of c after position i. 67 | */ 68 | virtual size_t selectNext(uint c, size_t i) const; 69 | 70 | /** Retrieve the symbol at position i. 71 | */ 72 | virtual uint access(size_t i) const; 73 | 74 | /** Retrieve the symbol at position i and its rank. 75 | */ 76 | virtual uint access(size_t i, size_t & r) const; 77 | 78 | /** Size of the structure in bytes. 79 | */ 80 | virtual size_t getSize() const = 0; 81 | 82 | /** Length of the sequence. 83 | */ 84 | virtual size_t getLength() const { return length; } 85 | 86 | /** Saves the structure to the stream 87 | */ 88 | virtual void save(ofstream & fp) const = 0; 89 | 90 | /** Reads a bitmap determining the type */ 91 | static Sequence * load(ifstream & fp); 92 | 93 | protected: 94 | size_t length; 95 | uint sigma; 96 | 97 | }; 98 | 99 | }; 100 | 101 | #include 102 | #include 103 | #include 104 | #include 105 | #include 106 | #include 107 | #include 108 | #include 109 | 110 | #include 111 | #endif /* _SEQUENCE_H */ 112 | -------------------------------------------------------------------------------- /include/SequenceAlphPart.h: -------------------------------------------------------------------------------- 1 | /* SequenceAlphPart.h 2 | * Copyright (C) 2010, Francisco Claude, all rights reserved. 3 | * 4 | * 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 _SEQUENCEALPHPART_H 23 | #define _SEQUENCEALPHPART_H 24 | 25 | #include 26 | #include 27 | 28 | using namespace cds_utils; 29 | using namespace std; 30 | 31 | namespace cds_static 32 | { 33 | 34 | /** Sequence Alphabet Partitioning 35 | * 36 | * @author Francisco Claude 37 | */ 38 | class SequenceAlphPart : public Sequence 39 | { 40 | 41 | public: 42 | 43 | SequenceAlphPart(uint * seq, size_t n, uint cut, SequenceBuilder * lenIndexBuilder, SequenceBuilder * seqsBuilder); 44 | SequenceAlphPart(const Array & values, uint cut, SequenceBuilder * lenIndexBuilder, SequenceBuilder * seqsBuilder); 45 | 46 | SequenceAlphPart(); 47 | 48 | virtual ~SequenceAlphPart(); 49 | 50 | virtual size_t rank(uint c, size_t i) const; 51 | 52 | virtual size_t select(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 size_t getLength() const { return length; } 59 | 60 | virtual void save(ofstream & fp) const; 61 | 62 | static SequenceAlphPart * load(ifstream & fp); 63 | 64 | protected: 65 | // reverse permutation for sorted symbols 66 | uint * revPermFreq; 67 | // symbols sorted by frequency 68 | uint * alphSortedByFreq; 69 | // the sequence indexing the lengths of the symbol in each position 70 | Sequence * groupsIndex; 71 | // sequences indexing the elements groupes by length 72 | Sequence ** indexesByLength; 73 | // cut corresponds to the number of symbols that are not represented in indexesByLength (the most frequent ones) 74 | uint cut; 75 | uint origsigma; 76 | // maxLen corresponds to the maximum length of a symbol in bits, 77 | // this-cut+1 corresponds to the maximum index in indexesByLength. 78 | uint maxLen; 79 | 80 | }; 81 | 82 | }; 83 | #endif /* _SEQUENCEALPHPART_H */ 84 | -------------------------------------------------------------------------------- /include/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 | 31 | class SequenceBuilder 32 | { 33 | public: 34 | SequenceBuilder() { userCount=0; } 35 | virtual ~SequenceBuilder() {} 36 | virtual Sequence * build(uint * seq, size_t len)=0; 37 | virtual Sequence * build(const Array & seq)=0; 38 | virtual void use() { userCount++; } 39 | virtual void unuse() { userCount--; assert(userCount>=0); if(userCount==0) delete this; } 40 | 41 | protected: 42 | int userCount; 43 | }; 44 | }; 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #endif 54 | -------------------------------------------------------------------------------- /include/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 | { 31 | class SequenceBuilderAlphPart : public SequenceBuilder 32 | { 33 | public: 34 | SequenceBuilderAlphPart(SequenceBuilder * groupIndexBuilder, SequenceBuilder * indexBuilder, uint cut); 35 | virtual ~SequenceBuilderAlphPart(); 36 | virtual Sequence * build(uint * seq, size_t len); 37 | virtual Sequence * build(const Array & seq); 38 | 39 | protected: 40 | SequenceBuilder * groupIndexBuilder; 41 | SequenceBuilder * indexBuilder; 42 | uint cut; 43 | }; 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /include/SequenceBuilderGMR.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderGMR.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 SequenceBuilderGMR_H 27 | #define SequenceBuilderGMR_H 28 | 29 | namespace cds_static 30 | { 31 | class SequenceBuilderGMR : public SequenceBuilder 32 | { 33 | public: 34 | SequenceBuilderGMR(BitSequenceBuilder * bsb, SequenceBuilder * sqb, uint chunk_len=0); 35 | virtual ~SequenceBuilderGMR(); 36 | virtual Sequence * build(uint * seq, size_t len); 37 | virtual Sequence * build(const Array & seq); 38 | 39 | protected: 40 | BitSequenceBuilder * bsb; 41 | SequenceBuilder * sqb; 42 | uint chunk_len; 43 | }; 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /include/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 | { 32 | class SequenceBuilderGMRChunk : public SequenceBuilder 33 | { 34 | public: 35 | SequenceBuilderGMRChunk(BitSequenceBuilder * bsb, PermutationBuilder * pmb); 36 | virtual ~SequenceBuilderGMRChunk(); 37 | virtual Sequence * build(uint * seq, size_t len); 38 | virtual Sequence * build(const Array & seq); 39 | 40 | protected: 41 | BitSequenceBuilder * bsb; 42 | PermutationBuilder * pmb; 43 | }; 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /include/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 | { 32 | class SequenceBuilderStr : public SequenceBuilder 33 | { 34 | public: 35 | SequenceBuilderStr(const string & options); 36 | virtual ~SequenceBuilderStr(); 37 | virtual Sequence * build(uint * seq, size_t len); 38 | virtual Sequence * build(const Array & seq); 39 | 40 | protected: 41 | virtual SequenceBuilder * getBuilder(const Array & seq); 42 | 43 | string str; 44 | }; 45 | }; 46 | #endif 47 | -------------------------------------------------------------------------------- /include/SequenceBuilderWaveletMatrix.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 SEQUENCEBUILDERWAVELETMATRIX_H 28 | #define SEQUENCEBUILDERWAVELETMATRIX_H 29 | 30 | namespace cds_static 31 | { 32 | class SequenceBuilderWaveletMatrix : public SequenceBuilder 33 | { 34 | public: 35 | SequenceBuilderWaveletMatrix(BitSequenceBuilder * bsb, Mapper * am); 36 | virtual ~SequenceBuilderWaveletMatrix(); 37 | virtual Sequence * build(uint * seq, size_t len); 38 | virtual Sequence * build(const Array & seq); 39 | 40 | protected: 41 | BitSequenceBuilder * bsb; 42 | Mapper * am; 43 | }; 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /include/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 | { 32 | class SequenceBuilderWaveletTree : public SequenceBuilder 33 | { 34 | public: 35 | SequenceBuilderWaveletTree(BitSequenceBuilder * bsb, Mapper * am, wt_coder * wc=NULL); 36 | virtual ~SequenceBuilderWaveletTree(); 37 | virtual Sequence * build(uint * seq, size_t len); 38 | virtual Sequence * build(const Array & seq); 39 | 40 | protected: 41 | BitSequenceBuilder * bsb; 42 | Mapper * am; 43 | wt_coder * wc; 44 | }; 45 | }; 46 | #endif 47 | -------------------------------------------------------------------------------- /include/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 | { 32 | class SequenceBuilderWaveletTreeNoptrs : public SequenceBuilder 33 | { 34 | public: 35 | SequenceBuilderWaveletTreeNoptrs(BitSequenceBuilder * bsb, Mapper * am); 36 | virtual ~SequenceBuilderWaveletTreeNoptrs(); 37 | virtual Sequence * build(uint * seq, size_t len); 38 | virtual Sequence * build(const Array & seq); 39 | 40 | protected: 41 | BitSequenceBuilder * bsb; 42 | Mapper * am; 43 | }; 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /include/SequenceBuilderWaveletTreeNoptrsS.h: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderWaveletTreeNoptrsS.h 2 | * Copyright (C) 2012, 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 SEQUENCEBUILDERWAVELETTREENOPTRSS_H 28 | #define SEQUENCEBUILDERWAVELETTREENOPTRSS_H 29 | 30 | namespace cds_static { 31 | class SequenceBuilderWaveletTreeNoptrsS : public SequenceBuilder { 32 | public: 33 | SequenceBuilderWaveletTreeNoptrsS(BitSequenceBuilder * bsb, Mapper * am); 34 | virtual ~SequenceBuilderWaveletTreeNoptrsS(); 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 | -------------------------------------------------------------------------------- /include/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 | { 36 | //using namespace std; 37 | 38 | class SequenceGMR : public Sequence 39 | { 40 | public: 41 | /** Builds the GMR structure. 42 | * @param sequence Sequence of unsigned ints 43 | * @param n length of the sequence 44 | * @param chunk_length length of the regular partitioning (called chunks in the paper) 45 | * @param bmb builder for the bitmap B (as called in the paper) 46 | * @param ssb builder for the representation used for each chunk. 47 | */ 48 | SequenceGMR(uint * sequence, size_t n, uint chunk_length, BitSequenceBuilder * bmb, SequenceBuilder * ssb); 49 | SequenceGMR(const Array & sequence, uint chunk_length, BitSequenceBuilder * bmb, SequenceBuilder * ssb); 50 | 51 | ~SequenceGMR(); 52 | virtual size_t rank(uint c, size_t j) const; 53 | virtual size_t select(uint c, size_t j) const; 54 | virtual uint access(size_t j) const; 55 | virtual size_t getSize() const; 56 | virtual void save(ofstream & fp) const; 57 | /** Loads the SequenceGMR object from the stream. 58 | */ 59 | static SequenceGMR * load(ifstream & fp); 60 | 61 | protected: 62 | SequenceGMR(); 63 | void build(uint * sequence, BitSequenceBuilder * bmb, SequenceBuilder * ssb); 64 | uint * get_ones(uint * sequence); 65 | 66 | uint sigma, chunk_length; 67 | Sequence ** chunk; 68 | BitSequence * B; 69 | }; 70 | 71 | }; 72 | #endif 73 | -------------------------------------------------------------------------------- /include/SequenceGMRChunk.h: -------------------------------------------------------------------------------- 1 | /* SequenceGMRChunk.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * gmr_chunk 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 SEQUENCEGMRCHUNK_H 23 | #define SEQUENCEGMRCHUNK_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace cds_static 35 | { 36 | //using namespace std; 37 | 38 | /** Implementation of the Chunk of Golynski et al's rank/select 39 | * data structure [1]. 40 | * 41 | * [1] A. Golynski and I. Munro and S. Rao. 42 | * Rank/select operations on large alphabets: a tool for text indexing. 43 | * SODA 06. 44 | * 45 | * @author Francisco Claude 46 | */ 47 | class SequenceGMRChunk: public Sequence 48 | { 49 | public: 50 | /** Builds the structures needed for the chunk 51 | * @param sequence sequence as array of unsigned integers. 52 | * @param chunk_length length of the sequence. 53 | * @param bmb bitmap builder for X (as named in the paper). 54 | * @param pmb permutation builder for Pi (as named in the paper). 55 | * */ 56 | SequenceGMRChunk(uint * sequence, uint chunk_length, BitSequenceBuilder *bmb, PermutationBuilder *pmb); 57 | SequenceGMRChunk(const Array & sequence, BitSequenceBuilder *bmb, PermutationBuilder *pmb); 58 | 59 | /** Destroy the chunk */ 60 | ~SequenceGMRChunk(); 61 | 62 | virtual uint access(size_t j) const; 63 | virtual size_t select(uint i, size_t j) const; 64 | virtual size_t rank(uint i, size_t j) const; 65 | virtual size_t getSize() const; 66 | virtual void save(ofstream & fp) const; 67 | static SequenceGMRChunk * load(ifstream & fp); 68 | 69 | protected: 70 | /** Bitmap */ 71 | BitSequence * X; 72 | /** Permutation */ 73 | Permutation * permutation; 74 | /** Size of the alphabet */ 75 | uint sigma; 76 | 77 | SequenceGMRChunk(); 78 | }; 79 | }; 80 | #endif 81 | -------------------------------------------------------------------------------- /include/TableOffsetRRR.h: -------------------------------------------------------------------------------- 1 | /* table_offset.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * Table for offsets 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 _TABLE_OFFSET_H 23 | #define _TABLE_OFFSET_H 24 | 25 | #include 26 | #include 27 | 28 | using namespace cds_utils; 29 | 30 | namespace cds_static 31 | { 32 | /** Universal table required for BitSequenceRRR, Raman, Raman and Rao's [1] 33 | * proposal for rank/select capable data structures, it achieves space nH_0, 34 | * O(sample_rate) time for rank and O(log len) for select. The practial implementation 35 | * is based on [2] 36 | * 37 | * [1] R. Raman, V. Raman and S. Rao. Succinct indexable dictionaries with applications 38 | * to encoding $k$-ary trees and multisets. SODA02. 39 | * [2] F. Claude and G. Navarro. Practical Rank/Select over Arbitrary Sequences. SPIRE08. 40 | * 41 | * @author Francisco Claude 42 | */ 43 | class table_offset 44 | { 45 | 46 | public: 47 | /** builds a universal table, designed for u<=15 */ 48 | table_offset(uint u); 49 | ~table_offset(); 50 | 51 | /** Increments the counter of users for the table */ 52 | inline void use() { 53 | users_count++; 54 | } 55 | 56 | /** Tells the object that the user is not going to need the table anymore. */ 57 | inline table_offset * unuse() { 58 | users_count--; 59 | if(!users_count) { 60 | delete this; 61 | return NULL; 62 | } 63 | return this; 64 | } 65 | 66 | /** Computes binomial(n,k) for n,k<=u */ 67 | inline uint get_binomial(uint n, uint k) { 68 | return binomial[n][k]; 69 | } 70 | 71 | /** Computes ceil(log2(binomial(n,k))) for n,k<=u */ 72 | inline ushort get_log2binomial(uint n, uint k) { 73 | return log2binomial[n][k]; 74 | } 75 | 76 | /** Returns the bitmap represented by the given class and inclass offsets */ 77 | inline ushort short_bitmap(uint class_offset, uint inclass_offset) { 78 | if(class_offset==0) return 0; 79 | if(class_offset==u) return (ushort)(((uint)1< 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | namespace cds_static 36 | { 37 | 38 | class WaveletMatrix : public Sequence 39 | { 40 | public: 41 | 42 | /** Builds a Wavelet Tree for the string 43 | * pointed by symbols assuming its length 44 | * equals n and uses bmb to build the bitsequence 45 | * @param bmb builder for the bitmaps in each level. 46 | * @param am alphabet mapper (we need all symbols to be used). 47 | * */ 48 | WaveletMatrix(uint * symbols, size_t n, BitSequenceBuilder * bmb, Mapper * am, bool deleteSymbols = false); 49 | WaveletMatrix(const Array &symbols2, BitSequenceBuilder * bmb, Mapper * am); 50 | 51 | // 52 | /** Destroys the Wavelet Tree */ 53 | virtual ~WaveletMatrix(); 54 | 55 | virtual size_t rank(uint symbol, size_t pos) const; 56 | virtual size_t select(uint symbol, size_t j) const; 57 | virtual uint access(size_t pos) const; 58 | virtual size_t getSize() const; 59 | 60 | virtual void save(ofstream & fp) const; 61 | static WaveletMatrix * load(ifstream & fp); 62 | 63 | protected: 64 | WaveletMatrix(); 65 | 66 | Mapper * am; 67 | 68 | BitSequence **bitstring; 69 | 70 | /** Length of the string. */ 71 | size_t n; 72 | 73 | /** Height of the Wavelet Tree. */ 74 | uint height, max_v; 75 | uint *C, *OCC; 76 | 77 | /** Obtains the maximum value from the string 78 | * symbols of length n */ 79 | uint max_value(uint *symbols, size_t n); 80 | 81 | /** How many bits are needed to represent val */ 82 | uint bits(uint val); 83 | 84 | /** Returns true if val has its ind-th bit set 85 | * to one. */ 86 | bool is_set(uint val, uint ind) const; 87 | 88 | /** Sets the ind-th bit in val */ 89 | uint set(uint val, uint ind) const; 90 | 91 | /** Recursive function for building the Wavelet Tree. */ 92 | void build_level(uint **bm, uint *symbols, uint length, uint *occs); 93 | }; 94 | }; 95 | #endif 96 | -------------------------------------------------------------------------------- /include/WaveletTreeNoptrsS.h: -------------------------------------------------------------------------------- 1 | /* WaveletTreeNoptrs.h 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * WaveletTreeNoptrs 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 _WVTREE_NOPTRSS_H 23 | #define _WVTREE_NOPTRSS_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | namespace cds_static 36 | { 37 | 38 | class WaveletTreeNoptrsS : public Sequence 39 | { 40 | public: 41 | 42 | /** Builds a Wavelet Tree for the string 43 | * pointed by symbols assuming its length 44 | * equals n and uses bmb to build the bitsequence 45 | * @param bmb builder for the bitmaps in each level. 46 | * @param am alphabet mapper (we need all symbols to be used). 47 | * */ 48 | WaveletTreeNoptrsS(uint * symbols, size_t n, BitSequenceBuilder * bmb, Mapper * am, bool deleteSymbols = false); 49 | WaveletTreeNoptrsS(const Array &symb, BitSequenceBuilder * bmb, Mapper * am); 50 | // 51 | /** Destroys the Wavelet Tree */ 52 | virtual ~WaveletTreeNoptrsS(); 53 | 54 | virtual size_t rank(uint symbol, size_t pos) const; 55 | virtual size_t select(uint symbol, size_t j) const; 56 | virtual uint access(size_t pos) const; 57 | virtual size_t getSize() const; 58 | 59 | size_t count(uint symbol) const; 60 | 61 | virtual void save(ofstream & fp) const; 62 | static WaveletTreeNoptrsS * load(ifstream & fp); 63 | 64 | protected: 65 | WaveletTreeNoptrsS(); 66 | 67 | Mapper * am; 68 | /** Only one bit-string for the Wavelet Tree. */ 69 | BitSequence **bitstring, *occ; 70 | 71 | /** Length of the string. */ 72 | size_t n; 73 | 74 | /** Height of the Wavelet Tree. */ 75 | uint height, max_v; 76 | 77 | /** Obtains the maximum value from the string 78 | * symbols of length n */ 79 | uint max_value(uint *symbols, size_t n); 80 | 81 | /** How many bits are needed to represent val */ 82 | uint bits(uint val); 83 | 84 | /** Returns true if val has its ind-th bit set 85 | * to one. */ 86 | bool is_set(uint val, uint ind) const; 87 | 88 | /** Sets the ind-th bit in val */ 89 | uint set(uint val, uint ind) const; 90 | 91 | /** Recursive function for building the Wavelet Tree. */ 92 | void build_level(uint **bm, uint *symbols, uint length, uint *occs); 93 | }; 94 | }; 95 | #endif 96 | -------------------------------------------------------------------------------- /include/cppUtils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CPPUTILS 3 | #define _CPPUTILS 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | using namespace std; 11 | 12 | namespace cds_utils 13 | { 14 | 15 | uint transform(const string & s); 16 | 17 | template void saveValue(ofstream & out, const T val) { 18 | assert(out.good()); 19 | out.write((char*)&val,sizeof(T)); 20 | } 21 | 22 | template T loadValue(ifstream & in) { 23 | assert(in.good()); 24 | T ret; 25 | in.read((char*)&ret,sizeof(T)); 26 | return ret; 27 | } 28 | 29 | template void saveValue(ofstream & out, const T * val, const size_t len) { 30 | assert(out.good()); 31 | out.write((char*)val,len*sizeof(T)); 32 | } 33 | 34 | template T * loadValue(ifstream & in, const size_t len) { 35 | assert(in.good()); 36 | T * ret = new T[len]; 37 | in.read((char*)ret,len*sizeof(T)); 38 | return ret; 39 | } 40 | 41 | template T * loadValue(const char * name, size_t & slen) { 42 | ifstream in(name); 43 | assert(in.good()); 44 | in.seekg(0,ios_base::end); 45 | size_t len = in.tellg(); 46 | slen = len/sizeof(T); 47 | if(len%sizeof(T)) slen--; 48 | in.seekg(0,ios_base::beg); 49 | T * ret = loadValue(in,slen); 50 | in.close(); 51 | return ret; 52 | } 53 | 54 | void tokenize(string str, vector &tokens, char delim); 55 | 56 | }; 57 | #endif 58 | -------------------------------------------------------------------------------- /include/huff.h: -------------------------------------------------------------------------------- 1 | /* huff.h 2 | Copyright (C) 2008, Gonzalo Navarro, all rights reserved. 3 | 4 | Canonical Huffman 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 HUFFINCLUDED 23 | #define HUFFINCLUDED 24 | 25 | #include 26 | #include 27 | 28 | using namespace cds_utils; 29 | 30 | namespace cds_static 31 | { 32 | 33 | typedef struct 34 | { // maximum symbol (0..max), same excluding zero freqs 35 | uint max,lim; 36 | uint depth; // max symbol length 37 | union 38 | { // symbol positions after sorting by decr freq (enc) 39 | uint *spos; 40 | uint *symb; // symbols sorted by freq (dec) 41 | } s; 42 | uint *num; // first pos of each length (dec), number of each length (enc) 43 | uint *fst; // first code (numeric) of each length (dec) 44 | unsigned long long total;// total length to achieve, in bits 45 | } THuff; 46 | 47 | /** Creates Huffman encoder given symbols 0..lim with frequencies 48 | * freq[i], ready for compression 49 | * 50 | * @author Gonzalo Navarro 51 | */ 52 | THuff createHuff (uint *freq, uint lim); 53 | 54 | /** Encodes symb using H, over stream[ptr...lim] (ptr and lim are 55 | * bit positions of stream). Returns the new ptr. 56 | * 57 | * @author Gonzalo Navarro 58 | */ 59 | size_t encodeHuff (const THuff H, uint symb, uint *stream, size_t ptr); 60 | 61 | /** Decodes *symb using H, over stream[ptr...lim] (ptr and lim are 62 | * bit positions of stream). Returns the new ptr. 63 | * 64 | * @author Gonzalo Navarro 65 | */ 66 | size_t decodeHuff (const THuff H, uint *symb, uint *stream, size_t ptr); 67 | 68 | /** Writes H in file f 69 | * 70 | * @author Gonzalo Navarro 71 | */ 72 | void saveHuff (const THuff H, ofstream & f); 73 | 74 | /** Size of H written on file 75 | * 76 | * @author Gonzalo Navarro 77 | */ 78 | uint sizeHuff (const THuff H); 79 | 80 | /** Frees H 81 | * 82 | * @author Gonzalo Navarro 83 | */ 84 | void freeHuff (THuff H); 85 | 86 | /** Loads H from file f, prepared for encoding or decoding depending 87 | * on enc 88 | * 89 | * @author Gonzalo Navarro 90 | */ 91 | THuff loadHuff (ifstream &f, int enc); 92 | 93 | }; 94 | #endif 95 | -------------------------------------------------------------------------------- /include/libcdsBitString.h: -------------------------------------------------------------------------------- 1 | /* libcdsBitString.h 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 | #ifndef BITSTRING_H2 23 | #define BITSTRING_H2 24 | 25 | #include 26 | 27 | #include 28 | 29 | using namespace std; 30 | 31 | namespace cds_utils 32 | { 33 | /** BitString class 34 | * @author Francisco Claude 35 | */ 36 | class BitString 37 | { 38 | public: 39 | 40 | /** Reads a BitString from a file stream 41 | * @param input input file stream 42 | */ 43 | BitString(ifstream & input); 44 | 45 | /** Creates a BitString with len bits of space */ 46 | BitString(const size_t len); 47 | 48 | /** Creates a bitmap from a vector (up to len bits) */ 49 | BitString(const vector fields, const size_t len); 50 | 51 | /** Creates a bitmap from an array (len bits) */ 52 | BitString(const uint * array, const size_t len); 53 | 54 | /** Destroys a bitmap */ 55 | ~BitString(); 56 | 57 | /** Sets the pos-th bit 58 | * @param pos position 59 | * @param bit value [0-1] 60 | */ 61 | inline void setBit(const size_t pos, const bool bit=true) { 62 | if(bit) bitset(data,pos); 63 | else bitclean(data,pos); 64 | } 65 | 66 | /** Gets the pos-th bit 67 | * @param pos position 68 | */ 69 | inline bool getBit(const size_t pos) const 70 | { 71 | return bitget(data,pos); 72 | } 73 | 74 | /** operator [] for getBit 75 | */ 76 | inline bool operator[](const size_t pos) const 77 | { 78 | return bitget(data,pos); 79 | } 80 | 81 | /** Saves the bitmap to a file 82 | * @param out file stream 83 | */ 84 | void save(ofstream & out) const; 85 | 86 | /** Returns the size in bytes of the BitString */ 87 | inline size_t getSize() const 88 | { 89 | return uintLength*sizeof(uint)+sizeof(this); 90 | } 91 | 92 | /** Returns the length in bits of the BitString */ 93 | inline size_t getLength() const 94 | { 95 | return length; 96 | } 97 | 98 | /** Returns a pointer to the buffer storing the values 99 | */ 100 | inline uint * getData() const 101 | { 102 | return data; 103 | } 104 | 105 | protected: 106 | size_t length; 107 | size_t uintLength; 108 | uint * data; 109 | 110 | /** Initializes the class fields */ 111 | void initData(const size_t len); 112 | }; 113 | }; 114 | #endif 115 | -------------------------------------------------------------------------------- /include/libcdsTrees.h: -------------------------------------------------------------------------------- 1 | #ifndef _BASICS_TREES_H 2 | #define _BASICS_TREES_H 3 | 4 | #include 5 | using namespace std; 6 | 7 | #define MAX(i,j) (((i) > (j)) ? (i) : (j)) 8 | 9 | namespace cds_utils 10 | { 11 | typedef unsigned char byte; 12 | 13 | static const unsigned int MAXINT=0x7fffffff; 14 | static const unsigned int FACT_RANK = 20; 15 | 16 | /** Retrieve a given index from array A where every value uses len bits 17 | * @param A Array 18 | * @param len Length in bits of each field 19 | * @param index Position to be retrieved 20 | * */ 21 | inline size_t get_field_64(uint *A, size_t len, size_t index) { 22 | if(len==0) return 0; 23 | uint result; 24 | long long i=1, j=1; 25 | i=i*index*len/W, j=j*index*len-W*i; 26 | if (j+len <= W) 27 | result = (A[i] << (W-j-len)) >> (W-len); 28 | else { 29 | result = A[i] >> j; 30 | result = result | (A[i+1] << (WW-j-len)) >> (W-len); 31 | } 32 | return (size_t)result; 33 | } 34 | 35 | inline void set_field_64(uint *A, size_t len, size_t index, size_t x) { 36 | if(len==0) return; 37 | long long i=1, j=1; 38 | i= i*index*len/W, j= j*index*len-i*W; 39 | uint mask = ((j+len) < W ? ~0u << (j+len) : 0) 40 | | ((W-j) < W ? ~0u >> (W-j) : 0); 41 | A[i] = (A[i] & mask) | x << j; 42 | if (j+len>W) { 43 | mask = ((~0u) << (len+j-W)); 44 | A[i+1] = (A[i+1] & mask)| x >> (W-j); 45 | } 46 | } 47 | 48 | /*Compute the longest common prefix between the suffix (with max length = lim) that starts in t1 and t2 49 | * @param text The text 50 | * @param t1 Position in the text where start the first suffix 51 | * @param t2 Position in the text where start the second suffix 52 | * @param lim Maximum value that can be returned 53 | * */ 54 | inline size_t lcp_length(char *text, size_t t1, size_t t2, size_t lim) { 55 | size_t cont=0; 56 | for(size_t i=0; i> p; 70 | if (len == W) { 71 | if (p) 72 | answ |= (*(e+1)) << (W-p); 73 | } 74 | else { 75 | if (p+len > W) 76 | answ |= (*(e+1)) << (W-p); 77 | answ &= (1<> (W-p)); 92 | } 93 | else { 94 | if (p+len <= W) { 95 | *e = (*e & ~(((1<> (W-p)); 101 | } 102 | } 103 | 104 | inline size_t loadText(char *filename, char **textt, size_t *length) { 105 | char *text; 106 | ifstream in(filename); 107 | if(!in.good()) 108 | return 1; 109 | in.seekg(0,ios_base::end); 110 | size_t len = in.tellg(); 111 | text = new char[len+1]; 112 | in.seekg(0,ios_base::beg); 113 | in.read(text,len); 114 | in.close(); 115 | text[len] = '\0'; 116 | *textt = text; 117 | *length = len+1; 118 | return 0; 119 | } 120 | 121 | }; 122 | #endif 123 | -------------------------------------------------------------------------------- /include/perm.h: -------------------------------------------------------------------------------- 1 | /* perm.h 2 | * Copyright (C) 2005, Diego Arroyuelo, all rights reserved. 3 | * Copyright (C) 2009, Francisco Claude 4 | * 5 | * Permutation 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 PERMINCLUDED 24 | #define PERMINCLUDED 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace cds_utils; 31 | 32 | namespace cds_static 33 | { 34 | 35 | typedef struct sperm 36 | { 37 | uint *elems; // elements of the permutation 38 | uint nelems; // # of elements 39 | BitSequence * bmap; // bitmap allowing rank() queries in O(1) time 40 | uint *bwdptrs; // array of backward pointers 41 | uint nbits; // log(nelems) 42 | uint nbwdptrs; // # of backward pointers 43 | uint t; 44 | } *perm; 45 | 46 | typedef struct 47 | { 48 | uint key; 49 | uint pointer; 50 | } auxbwd; 51 | 52 | /** Creates a permutation 53 | * 54 | * @author Diego Arroyuelo 55 | */ 56 | perm createPerm(uint *elems, uint nelems, uint t, BitSequenceBuilder * bmb); 57 | 58 | /** Gets the i-th element of the permutation 59 | * 60 | * @author Diego Arroyuelo 61 | */ 62 | uint getelemPerm(const perm P, uint i); 63 | 64 | /** Destroys a permutation 65 | * 66 | * @author Diego Arroyuelo 67 | */ 68 | void destroyPerm(perm P); 69 | 70 | /** Get pi(i)^{-1} 71 | * 72 | * @author Diego Arroyuelo 73 | */ 74 | uint inversePerm(const perm P, uint i); 75 | 76 | /** Saves a permutation 77 | * 78 | * @author Diego Arroyuelo 79 | */ 80 | uint savePerm(const perm P, ofstream & f); 81 | 82 | /** Loads a permutation 83 | * 84 | * @author Diego Arroyuelo 85 | */ 86 | perm loadPerm(ifstream & f); 87 | 88 | /** Returns the size of the data structure 89 | * 90 | * @author Diego Arroyuelo 91 | */ 92 | uint sizeofPerm(const perm P); 93 | 94 | }; 95 | #endif 96 | -------------------------------------------------------------------------------- /include/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 | -------------------------------------------------------------------------------- /include/timing.h: -------------------------------------------------------------------------------- 1 | /* timing.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 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace std; 35 | 36 | namespace cds_utils 37 | { 38 | /** Resets the system timer (yes, we only have one) 39 | */ 40 | void start_timing(); 41 | 42 | /** Obtains the number of milliseconds since the last timer start 43 | */ 44 | double get_timing(); 45 | 46 | }; 47 | -------------------------------------------------------------------------------- /include/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 | virtual bool is_set(uint *symbol, uint l) const=0; 53 | /** Tells if the path of symbol becomes unique at level l */ 54 | virtual bool done(uint symbol, uint l) const =0; 55 | virtual uint * get_symbol(uint symbol) const = 0; 56 | /** Returns the size of the coder */ 57 | virtual size_t getSize() const = 0; 58 | /** Returns the depth of the tree */ 59 | virtual uint depth() const 60 | { 61 | return -1; // Implemented in wt_coder_binary 62 | } 63 | /** Saves the coder to a file, returns 0 in case of success */ 64 | virtual void save(ofstream & fp) const = 0; 65 | /** Loads a coder from a file, returns NULL in case of error */ 66 | static wt_coder * load(ifstream & fp); 67 | protected: 68 | uint user_count; 69 | }; 70 | 71 | }; 72 | 73 | #include 74 | #include 75 | #endif 76 | -------------------------------------------------------------------------------- /include/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 is_set(uint *symbol, uint l) const; 49 | virtual bool done(uint symbol, uint l) const; 50 | virtual uint depth() const{ return h; } 51 | virtual uint * get_symbol(uint symbol) const; 52 | virtual size_t getSize() const; 53 | virtual void save(ofstream & fp) const; 54 | static wt_coder_binary * load(ifstream & fp); 55 | 56 | protected: 57 | wt_coder_binary(); 58 | uint h; 59 | }; 60 | }; 61 | #endif 62 | -------------------------------------------------------------------------------- /include/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 is_set(uint *symbol, uint l) const; 48 | virtual bool done(uint symbol, uint l) const; 49 | virtual size_t getSize() const; 50 | virtual uint * get_symbol(uint symbol) const; 51 | virtual void save(ofstream & fp) const; 52 | static wt_coder_huff * load(ifstream & fp); 53 | //uint * get_buffer(uint symbol, uint *n); 54 | 55 | protected: 56 | wt_coder_huff(); 57 | HuffmanCoder * hc; 58 | uint maxBuffer; 59 | }; 60 | }; 61 | #endif 62 | -------------------------------------------------------------------------------- /include/wt_node.h: -------------------------------------------------------------------------------- 1 | /* wt_node.h 2 | * Copyright (C) 2008, Francisco Claude. 3 | * Copyright (C) 2011, Matthias Petri. 4 | * 5 | * wt_node 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 wt_node_h 24 | #define wt_node_h 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace cds_utils; 31 | 32 | namespace cds_static 33 | { 34 | 35 | #define WT_NODE_NULL_HDR 0 36 | #define WT_NODE_INTERNAL_HDR 2 37 | #define WT_NODE_LEAF_HDR 3 38 | 39 | /** Base clase for nodes in the wavelet tree 40 | * 41 | * @author Francisco Claude 42 | */ 43 | class wt_node 44 | { 45 | public: 46 | virtual ~wt_node() {} 47 | virtual size_t rank(uint *symbol, size_t pos, uint l, wt_coder *c) const = 0; 48 | virtual size_t select(uint *symbol, size_t pos, uint l, wt_coder *c) const = 0; 49 | virtual pair quantile_freq(size_t left,size_t right,uint q) const = 0; 50 | virtual uint access(size_t pos) const = 0; 51 | virtual uint access(size_t pos, size_t & rankp) const = 0; 52 | virtual size_t getSize() const = 0; 53 | virtual void save(ofstream & fp) const = 0; 54 | static wt_node * load(ifstream & fp); 55 | }; 56 | 57 | }; 58 | 59 | #include 60 | #include 61 | #endif 62 | -------------------------------------------------------------------------------- /include/wt_node_internal.h: -------------------------------------------------------------------------------- 1 | /* wt_node_internal.h 2 | * Copyright (C) 2008, Francisco Claude. 3 | * Copyright (C) 2011, Matthias Petri. 4 | * 5 | * wt_node_internal 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 wt_node_internal_h 24 | #define wt_node_internal_h 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace cds_static 33 | { 34 | 35 | /** Class for representing internal nodes 36 | * 37 | * @author Francisco Claude 38 | */ 39 | class wt_node_internal: public wt_node 40 | { 41 | public: 42 | wt_node_internal(uint * seq, size_t n, uint l, wt_coder * c, BitSequenceBuilder * bmb); 43 | wt_node_internal(uchar * seq, size_t n, uint l, wt_coder * c, BitSequenceBuilder * bmb, size_t left, uint * done); 44 | virtual ~wt_node_internal(); 45 | virtual size_t rank(uint *symbol, size_t pos, uint level, wt_coder *c) const; 46 | //virtual size_t rankLessThan(uint &symbol, size_t pos) const; 47 | virtual size_t select(uint *symbol, size_t pos, uint level, wt_coder *c) const; 48 | virtual pair quantile_freq(size_t left,size_t right,uint q) const; 49 | virtual uint access(size_t pos) const; 50 | virtual uint access(size_t pos, size_t & rankp) const; 51 | virtual size_t getSize() const; 52 | virtual void save(ofstream & fp) const; 53 | static wt_node_internal * load(ifstream & fp); 54 | 55 | protected: 56 | wt_node_internal(); 57 | wt_node *left_child, *right_child; 58 | BitSequence * bitmap; 59 | //uint length; 60 | }; 61 | }; 62 | #endif 63 | -------------------------------------------------------------------------------- /include/wt_node_leaf.h: -------------------------------------------------------------------------------- 1 | /* wt_node_leaf.h 2 | * Copyright (C) 2008, Francisco Claude. 3 | * Copyright (C) 2011, Matthias Petri. 4 | * 5 | * wt_node_leaf 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 wt_node_leaf_h 24 | #define wt_node_leaf_h 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace cds_static 33 | { 34 | 35 | /** Class for representing leaves of the wavelet tree. 36 | * 37 | * @author Francisco Claude 38 | */ 39 | class wt_node_leaf: public wt_node 40 | { 41 | public: 42 | wt_node_leaf(uint symbol, size_t count); 43 | virtual ~wt_node_leaf(); 44 | virtual size_t rank(uint *symbol, size_t pos, uint l, wt_coder *c) const; 45 | virtual size_t select(uint *symbol, size_t pos, uint l, wt_coder *c) const; 46 | virtual pair quantile_freq(size_t left,size_t right,uint q) const; 47 | virtual uint access(size_t pos) const; 48 | virtual uint access(size_t pos, size_t &rank) const; 49 | virtual size_t getSize() const; 50 | virtual void save(ofstream & fp) const; 51 | static wt_node_leaf * load(ifstream & fp); 52 | 53 | protected: 54 | wt_node_leaf(); 55 | uint symbol; 56 | size_t count; 57 | }; 58 | }; 59 | #endif 60 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # This Makefile builds the libcds library. 2 | 3 | AM_CPPFLAGS = -I../include/ 4 | 5 | lib_LTLIBRARIES = libcds.la 6 | libcds_la_LDFLAGS = -version-info $(CDS_SO_VERSION) 7 | libcds_la_SOURCES = \ 8 | static/bitsequence/BitSequenceBuilderDArray.cpp \ 9 | static/bitsequence/BitSequenceBuilderRG.cpp \ 10 | static/bitsequence/BitSequenceBuilderRRR.cpp \ 11 | static/bitsequence/BitSequenceBuilderSDArray.cpp \ 12 | static/bitsequence/BitSequence.cpp \ 13 | static/bitsequence/BitSequenceDArray.cpp \ 14 | static/bitsequence/BitSequenceRG.cpp \ 15 | static/bitsequence/BitSequenceRRR.cpp \ 16 | static/bitsequence/BitSequenceSDArray.cpp \ 17 | static/bitsequence/sdarraySadakane.cpp \ 18 | static/bitsequence/TableOffsetRRR.cpp \ 19 | static/coders/huff.cpp \ 20 | static/coders/HuffmanCoder.cpp \ 21 | static/mapper/MapperCont.cpp \ 22 | static/mapper/Mapper.cpp \ 23 | static/mapper/MapperNone.cpp \ 24 | static/mapper/MapperRev.cpp \ 25 | static/permutation/perm.cpp \ 26 | static/permutation/PermutationBuilderMRRR.cpp \ 27 | static/permutation/PermutationBuilderWT.cpp \ 28 | static/permutation/Permutation.cpp \ 29 | static/permutation/PermutationMRRR.cpp \ 30 | static/permutation/PermutationWT.cpp \ 31 | static/sequence/BitmapsSequence.cpp \ 32 | static/sequence/SequenceAlphPart.cpp \ 33 | static/sequence/SequenceBuilderAlphPart.cpp \ 34 | static/sequence/SequenceBuilderGMRChunk.cpp \ 35 | static/sequence/SequenceBuilderGMR.cpp \ 36 | static/sequence/SequenceBuilderStr.cpp \ 37 | static/sequence/SequenceBuilderWaveletMatrix.cpp \ 38 | static/sequence/SequenceBuilderWaveletTree.cpp \ 39 | static/sequence/SequenceBuilderWaveletTreeNoptrs.cpp \ 40 | static/sequence/SequenceBuilderWaveletTreeNoptrsS.cpp \ 41 | static/sequence/Sequence.cpp \ 42 | static/sequence/SequenceGMRChunk.cpp \ 43 | static/sequence/SequenceGMR.cpp \ 44 | static/sequence/WaveletMatrix.cpp \ 45 | static/sequence/WaveletTree.cpp \ 46 | static/sequence/WaveletTreeNoptrs.cpp \ 47 | static/sequence/WaveletTreeNoptrsS.cpp \ 48 | static/sequence/wt_coder_binary.cpp \ 49 | static/sequence/wt_coder.cpp \ 50 | static/sequence/wt_coder_huff.cpp \ 51 | static/sequence/wt_node.cpp \ 52 | static/sequence/wt_node_internal.cpp \ 53 | static/sequence/wt_node_leaf.cpp \ 54 | utils/Array.cpp \ 55 | utils/cppUtils.cpp \ 56 | utils/libcdsBitString.cpp \ 57 | utils/timing.cpp 58 | -------------------------------------------------------------------------------- /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 | }; 44 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/static/bitsequence/BitSequenceSDArray.cpp: -------------------------------------------------------------------------------- 1 | /* BitSequenceSDArray.cpp 2 | * Copyright (C) 2009, Francisco Claude, all rights reserved. 3 | * 4 | * Francisco Claude 5 | * 6 | * This class is a wrapper for sdarraySadakane.cpp, which was implemented 7 | * 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 | #include 26 | 27 | namespace cds_static 28 | { 29 | BitSequenceSDArray::BitSequenceSDArray(const BitString & bs) { 30 | uint * tmp_seq = new uint[uint_len(bs.getLength(),1)+1]; 31 | ones = 0; 32 | for(uint i=0;ilength = bs.getLength(); 42 | delete [] tmp_seq; 43 | } 44 | 45 | BitSequenceSDArray::BitSequenceSDArray(uint * buff, size_t len) { 46 | uint * tmp_seq = new uint[uint_len(len,1)+1]; 47 | ones = 0; 48 | for(uint i=0;ilength = len; 58 | delete [] tmp_seq; 59 | } 60 | 61 | BitSequenceSDArray::BitSequenceSDArray() { 62 | make___selecttbl(); 63 | } 64 | 65 | BitSequenceSDArray::~BitSequenceSDArray() { 66 | if(ones) 67 | selects3_free(&sd); 68 | } 69 | 70 | size_t BitSequenceSDArray::rank1(size_t i) const 71 | { 72 | if(i>=length) return -1; 73 | if(ones) 74 | return selects3_rank(&sd,i); 75 | else 76 | return 0; 77 | } 78 | 79 | size_t BitSequenceSDArray::select1(size_t i) const 80 | { 81 | if(i>ones || i==0) return -1; 82 | if(ones) 83 | return selects3_select(&sd,(uint)i); 84 | else 85 | return (uint)-1; 86 | } 87 | 88 | size_t BitSequenceSDArray::selectNext1(size_t i) const 89 | { 90 | return selects3_selectnext(&sd,(uint)i); 91 | } 92 | 93 | size_t BitSequenceSDArray::getSize() const 94 | { 95 | return sizeof(BitSequenceSDArray)+(ones?(sd.size + sd.sd0->size + sd.sd1->size):0); 96 | } 97 | 98 | void BitSequenceSDArray::save(ofstream & fp) const 99 | { 100 | uint wr = SDARRAY_HDR; 101 | saveValue(fp,wr); 102 | saveValue(fp,length); 103 | saveValue(fp,ones); 104 | if(ones) 105 | selects3_save(&sd,fp); 106 | } 107 | 108 | BitSequenceSDArray * BitSequenceSDArray::load(ifstream & fp) { 109 | uint id = loadValue(fp); 110 | if(id!=SDARRAY_HDR) return NULL; 111 | BitSequenceSDArray * ret = new BitSequenceSDArray(); 112 | ret->length = loadValue(fp); 113 | ret->ones = loadValue(fp); 114 | if(ret->ones) 115 | selects3_load(&ret->sd,fp); 116 | return ret; 117 | } 118 | 119 | }; 120 | -------------------------------------------------------------------------------- /src/static/coders/HuffmanCoder.cpp: -------------------------------------------------------------------------------- 1 | /* HuffmanCoder.cpp 2 | Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | 4 | Wrapper for huff written by Gonzalo Navarro 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 | using namespace cds_utils; 27 | 28 | HuffmanCoder::HuffmanCoder(uint * symb, size_t n) { 29 | uint max_v = 0; 30 | for(size_t i=0;i(fp,HUFF_HDR); 95 | saveHuff(huff_table,fp); 96 | } 97 | 98 | HuffmanCoder * HuffmanCoder::load(ifstream & fp) { 99 | uint type = loadValue(fp); 100 | if(type != HUFF_HDR) { //throw exception 101 | return NULL; 102 | } 103 | HuffmanCoder * ret = new HuffmanCoder(); 104 | ret->huff_table = loadHuff(fp,1); 105 | return ret; 106 | } 107 | 108 | }; 109 | -------------------------------------------------------------------------------- /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 | case MAPPER_REV_HDR: return MapperRev::load(input); 50 | } 51 | return NULL; 52 | } 53 | }; 54 | -------------------------------------------------------------------------------- /src/static/mapper/MapperCont.cpp: -------------------------------------------------------------------------------- 1 | /* alphabet_mapper_cont.cpp 2 | * Copyright (C) 2008, Francisco Claude, all rights reserved. 3 | * 4 | * alphabet_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 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | MapperCont::MapperCont(const Array & seq, const BitSequenceBuilder & bmb) { 28 | BitString bs(seq.getMax()+1); 29 | for(size_t i=0;irank1(s); 56 | } 57 | 58 | uint MapperCont::unmap(uint s) const 59 | { 60 | return m->select1(s); 61 | } 62 | 63 | size_t MapperCont::getSize() const 64 | { 65 | return sizeof(MapperCont)+m->getSize(); 66 | } 67 | 68 | void MapperCont::save(ofstream & out) const 69 | { 70 | assert(out.good()); 71 | uint wr = MAPPER_CONT_HDR; 72 | saveValue(out,wr); 73 | m->save(out); 74 | } 75 | 76 | MapperCont * MapperCont::load(ifstream & input) { 77 | assert(input.good()); 78 | uint rd = loadValue(input); 79 | if(rd!=MAPPER_CONT_HDR) return NULL; 80 | MapperCont * ret = new MapperCont(); 81 | ret->m = BitSequence::load(input); 82 | if(ret->m==NULL) { 83 | delete ret; 84 | return NULL; 85 | } 86 | return ret; 87 | } 88 | }; 89 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/static/mapper/MapperRev.cpp: -------------------------------------------------------------------------------- 1 | /* MapperRev.cpp 2 | * Copyright (C) 2012, Francisco Claude, all rights reserved. 3 | * 4 | * MapperRev 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 | using namespace cds_utils; 26 | 27 | namespace cds_static 28 | { 29 | 30 | // based on http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv 31 | uint reverse(const uint v) { 32 | uint res = v; 33 | const uchar *c = (const uchar*)&v; 34 | uchar *c2 = (uchar*)&res; 35 | c2[0] = (c[3] * 0x0202020202ULL & 0x010884422010ULL) % 1023; 36 | c2[1] = (c[2] * 0x0202020202ULL & 0x010884422010ULL) % 1023; 37 | c2[2] = (c[1] * 0x0202020202ULL & 0x010884422010ULL) % 1023; 38 | c2[3] = (c[0] * 0x0202020202ULL & 0x010884422010ULL) % 1023; 39 | return res; 40 | } 41 | 42 | MapperRev::MapperRev() { } 43 | MapperRev::MapperRev(const Array &a) { 44 | uint maxv = 0; 45 | for(uint i=0; i < a.getLength(); i++) 46 | maxv = max(maxv, a.getField(i)); 47 | this->bits = cds_utils::bits(maxv); 48 | } 49 | 50 | MapperRev::MapperRev(const uint *A, const size_t len) { 51 | uint maxv = 0; 52 | for(uint i=0; i < len; i++) 53 | maxv = max(maxv, A[i]); 54 | this->bits = cds_utils::bits(maxv); 55 | } 56 | 57 | uint MapperRev::map(const uint s) const { 58 | uint rev = reverse(s); 59 | return rev >> (31 - this->bits); 60 | } 61 | 62 | uint MapperRev::unmap(const uint s) const {return map(s);} 63 | 64 | size_t MapperRev::getSize() const { return sizeof(MapperNone); } 65 | 66 | void MapperRev::save(ofstream & out) const 67 | { 68 | uint wr = MAPPER_REV_HDR; 69 | out.write((char*)&wr,sizeof(uint)); 70 | out.write((char*)&this->bits,sizeof(uint)); 71 | } 72 | 73 | MapperRev * MapperRev::load(ifstream & input) { 74 | uint rd; 75 | input.read((char*)&rd,sizeof(uint)); 76 | if(rd!=MAPPER_REV_HDR) return NULL; 77 | MapperRev * ret = new MapperRev(); 78 | input.read((char*)&ret->bits, sizeof(uint)); 79 | return ret; 80 | } 81 | }; 82 | -------------------------------------------------------------------------------- /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 | #include 22 | 23 | namespace cds_static 24 | { 25 | 26 | Permutation::Permutation() { length = 0; } 27 | 28 | Permutation::~Permutation() {} 29 | 30 | uint Permutation::pi(uint i) const 31 | { 32 | return pi(i,1); 33 | } 34 | 35 | uint Permutation::revpi(uint i) const 36 | { 37 | return revpi(i,1); 38 | } 39 | 40 | uint Permutation::pi(uint i, uint k) const 41 | { 42 | uint ret = i; 43 | while(k-->0) 44 | ret = pi(ret); 45 | return ret; 46 | } 47 | 48 | uint Permutation::revpi(uint i, uint k) const 49 | { 50 | uint ret = i; 51 | while(k-->0) 52 | ret = revpi(ret); 53 | return ret; 54 | } 55 | 56 | size_t Permutation::getLength() const 57 | { 58 | return length; 59 | } 60 | 61 | void Permutation::save(ofstream & fp) const 62 | { 63 | saveValue(fp,length); 64 | } 65 | 66 | Permutation * Permutation::load(ifstream & fp) { 67 | uint rd = loadValue(fp); 68 | size_t pos = fp.tellg(); 69 | fp.seekg(pos - sizeof(uint),ios::beg); 70 | switch(rd) { 71 | case MRRRPERM: return PermutationMRRR::load(fp); 72 | break; 73 | case WTPERM: return PermutationWT::load(fp); 74 | break; 75 | } 76 | return NULL; 77 | } 78 | 79 | }; 80 | -------------------------------------------------------------------------------- /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 | { 26 | PermutationBuilderMRRR::PermutationBuilderMRRR(uint sample, BitSequenceBuilder * bmb) { 27 | this->sample = sample; 28 | this->bmb = bmb; 29 | bmb->use(); 30 | } 31 | 32 | PermutationBuilderMRRR::~PermutationBuilderMRRR() { 33 | bmb->unuse(); 34 | } 35 | 36 | Permutation * PermutationBuilderMRRR::build(uint * perm, uint len) const 37 | { 38 | return new PermutationMRRR(perm,len,sample,bmb); 39 | } 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /src/static/permutation/PermutationBuilderWT.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * PermutationBuilderWT.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | namespace cds_static 22 | { 23 | Permutation * PermutationBuilderWT::build(uint * perm, uint len) const 24 | { 25 | return new PermutationWT(perm,len); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /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 | #include 23 | 24 | namespace cds_static 25 | { 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 | { 40 | return sizeof(PermutationMRRR)+sizeofPerm(permutation); 41 | } 42 | 43 | uint PermutationMRRR::pi(uint i) const 44 | { 45 | return getelemPerm(permutation,i); 46 | } 47 | 48 | uint PermutationMRRR::revpi(uint i) const 49 | { 50 | return inversePerm(permutation,i); 51 | } 52 | 53 | void PermutationMRRR::save(ofstream & fp) const 54 | { 55 | uint wr = MRRRPERM; 56 | saveValue(fp,wr); 57 | savePerm(permutation,fp); 58 | } 59 | 60 | PermutationMRRR * PermutationMRRR::load(ifstream & fp) { 61 | uint rd = loadValue(fp); 62 | if(rd!=MRRRPERM) return NULL; 63 | PermutationMRRR * ret = new PermutationMRRR(); 64 | ret->permutation = loadPerm(fp); 65 | return ret; 66 | } 67 | 68 | }; 69 | -------------------------------------------------------------------------------- /src/static/permutation/PermutationWT.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * PermutationWT.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | namespace cds_static 22 | { 23 | 24 | PermutationWT::PermutationWT(uint *perm, size_t len) { 25 | uint b = bits(len-1); 26 | uint * seq = new uint[len]; 27 | uint * marker = new uint[uint_len(len,1)]; 28 | for(size_t i=0;i get_field(perm,b,i)) { 38 | runs++; 39 | cds_utils::bitset(marker,i); 40 | } 41 | seq[get_field(perm,b,i)] = runs; 42 | last = get_field(perm,b,i); 43 | } 44 | 45 | wt = new WaveletTreeNoptrs(seq, len, new BitSequenceBuilderRRR(40), new MapperNone()); 46 | marks = new BitSequenceRG(marker, len, 20); 47 | delete [] seq; 48 | } 49 | 50 | PermutationWT::~PermutationWT() { 51 | delete wt; 52 | } 53 | 54 | uint PermutationWT::pi(uint k) const 55 | { 56 | uint v = (uint)marks->rank1(k); 57 | return (uint)wt->select(v-1, k - marks->select1(v) + 1); 58 | } 59 | 60 | uint PermutationWT::revpi(uint k) const 61 | { 62 | size_t val = 0; 63 | uint s = wt->access(k, val); 64 | return marks->select1(s+1) + val - 1; 65 | } 66 | 67 | size_t PermutationWT::getSize() const 68 | { 69 | return marks->getSize()+wt->getSize()+sizeof(PermutationWT); 70 | } 71 | 72 | void PermutationWT::save(ofstream & out) const 73 | { 74 | saveValue(out,WTPERM); 75 | saveValue(out, length); 76 | wt->save(out); 77 | marks->save(out); 78 | } 79 | 80 | PermutationWT * PermutationWT::load(ifstream &in) { 81 | uint rd = loadValue(in); 82 | if(rd!=WTPERM) return NULL; 83 | PermutationWT * ret = new PermutationWT(); 84 | ret->length = loadValue(in); 85 | ret->wt = Sequence::load(in); 86 | ret->marks = BitSequence::load(in); 87 | return ret; 88 | } 89 | }; 90 | -------------------------------------------------------------------------------- /src/static/sequence/Sequence.cpp: -------------------------------------------------------------------------------- 1 | /* Sequence.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 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace cds_static 32 | { 33 | 34 | Sequence::Sequence(size_t _length) { 35 | length = _length; 36 | } 37 | 38 | size_t Sequence::rank(uint c, size_t i) const 39 | { 40 | size_t count = 0; 41 | for(size_t k=0;k<=i;k++) 42 | if(access(k)==c) count++; 43 | return count; 44 | } 45 | 46 | size_t Sequence::select(uint c, size_t j) const 47 | { 48 | size_t count = 0; 49 | for(size_t k=0;k0)?rank(k,i-1):0) 67 | for(uint k=0;kprev(k)) return k; 69 | } 70 | // throw exception 71 | return (uint)-1; 72 | } 73 | 74 | uint Sequence::access(size_t i, size_t & _rank) const 75 | { 76 | uint s = access(i); 77 | _rank = rank(s,i); 78 | return s; 79 | } 80 | 81 | Sequence * Sequence::load(ifstream & fp) { 82 | uint type = loadValue(fp); 83 | size_t pos = fp.tellg(); 84 | fp.seekg(pos-sizeof(uint),ios::beg); 85 | switch(type) { 86 | case GMR_CHUNK_HDR: return SequenceGMRChunk::load(fp); 87 | case GMR_HDR: return SequenceGMR::load(fp); 88 | case BS_HDR: return BitmapsSequence::load(fp); 89 | case WVTREE_HDR: return WaveletTree::load(fp); 90 | case WVTREE_NOPTRS_HDR: return WaveletTreeNoptrs::load(fp); 91 | case ALPHPART_HDR: return SequenceAlphPart::load(fp); 92 | case WVMATRIX_HDR: return WaveletMatrix::load(fp); 93 | } 94 | return NULL; 95 | } 96 | 97 | }; 98 | -------------------------------------------------------------------------------- /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 | 26 | SequenceBuilderAlphPart::SequenceBuilderAlphPart(SequenceBuilder * groupIndexBuilder, SequenceBuilder * indexBuilder, uint cut) { 27 | this->groupIndexBuilder = groupIndexBuilder; 28 | this->indexBuilder = indexBuilder; 29 | this->cut = cut; 30 | groupIndexBuilder->use(); 31 | indexBuilder->use(); 32 | } 33 | 34 | SequenceBuilderAlphPart::~SequenceBuilderAlphPart() { 35 | groupIndexBuilder->unuse(); 36 | indexBuilder->unuse(); 37 | } 38 | 39 | Sequence * SequenceBuilderAlphPart::build(uint * sequence, size_t len) { 40 | return new SequenceAlphPart(sequence,len,cut,groupIndexBuilder,indexBuilder); 41 | } 42 | 43 | Sequence * SequenceBuilderAlphPart::build(const Array & seq) { 44 | return new SequenceAlphPart(seq,cut,groupIndexBuilder,indexBuilder); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /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 | 26 | SequenceBuilderGMR::SequenceBuilderGMR(BitSequenceBuilder * bsb, SequenceBuilder * sqb, uint chunk_len) { 27 | this->bsb = bsb; 28 | this->sqb = sqb; 29 | this->chunk_len = chunk_len; 30 | bsb->use(); 31 | sqb->use(); 32 | } 33 | 34 | SequenceBuilderGMR::~SequenceBuilderGMR() { 35 | bsb->unuse(); 36 | sqb->unuse(); 37 | } 38 | 39 | Sequence * SequenceBuilderGMR::build(uint * sequence, size_t len) { 40 | uint cl = chunk_len; 41 | if(chunk_len==0) { 42 | uint s=0; 43 | 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 | namespace cds_static 24 | { 25 | 26 | SequenceBuilderGMRChunk::SequenceBuilderGMRChunk(BitSequenceBuilder * bsb, PermutationBuilder * pmb) { 27 | this->bsb = bsb; 28 | this->pmb = pmb; 29 | bsb->use(); 30 | pmb->use(); 31 | } 32 | 33 | SequenceBuilderGMRChunk::~SequenceBuilderGMRChunk() { 34 | bsb->unuse(); 35 | pmb->unuse(); 36 | } 37 | 38 | Sequence * SequenceBuilderGMRChunk::build(uint * sequence, size_t len) { 39 | return new SequenceGMRChunk(sequence, len, bsb, pmb); 40 | } 41 | 42 | Sequence * SequenceBuilderGMRChunk::build(const Array & seq) { 43 | return new SequenceGMRChunk(seq, bsb, pmb); 44 | } 45 | 46 | }; 47 | -------------------------------------------------------------------------------- /src/static/sequence/SequenceBuilderWaveletMatrix.cpp: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderWaveletMatrix.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 | 26 | SequenceBuilderWaveletMatrix::SequenceBuilderWaveletMatrix(BitSequenceBuilder * bsb, Mapper * am) { 27 | this->bsb = bsb; 28 | this->am = am; 29 | bsb->use(); 30 | am->use(); 31 | } 32 | 33 | SequenceBuilderWaveletMatrix::~SequenceBuilderWaveletMatrix() { 34 | bsb->unuse(); 35 | am->unuse(); 36 | } 37 | 38 | Sequence * SequenceBuilderWaveletMatrix::build(uint * sequence, size_t len) { 39 | return new WaveletMatrix(sequence, len, bsb, am); 40 | } 41 | 42 | Sequence * SequenceBuilderWaveletMatrix::build(const Array & seq) { 43 | return new WaveletMatrix(seq, bsb, am); 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /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 | 26 | SequenceBuilderWaveletTree::SequenceBuilderWaveletTree(BitSequenceBuilder * bsb, Mapper * am, wt_coder * wc) { 27 | this->bsb = bsb; 28 | this->am = am; 29 | this->wc = wc; 30 | bsb->use(); 31 | am->use(); 32 | if(wc!=NULL) 33 | wc->use(); 34 | } 35 | 36 | SequenceBuilderWaveletTree::~SequenceBuilderWaveletTree() { 37 | bsb->unuse(); 38 | am->unuse(); 39 | if(wc!=NULL) 40 | wc->unuse(); 41 | } 42 | 43 | Sequence * SequenceBuilderWaveletTree::build(uint * sequence, size_t len) { 44 | Sequence * ret; 45 | if(wc==NULL) { 46 | wt_coder * wcaux = new wt_coder_huff(sequence,len,am); 47 | wcaux->use(); 48 | ret = new WaveletTree(sequence, len, wcaux, bsb, am); 49 | wcaux->unuse(); 50 | } 51 | else { 52 | ret = new WaveletTree(sequence, len, wc, bsb, am); 53 | } 54 | return ret; 55 | } 56 | 57 | Sequence * SequenceBuilderWaveletTree::build(const Array & seq) { 58 | Sequence * ret; 59 | if(wc==NULL) { 60 | wt_coder * wcaux = new wt_coder_huff(seq,am); 61 | wcaux->use(); 62 | ret = new WaveletTree(seq, wcaux, bsb, am); 63 | wcaux->unuse(); 64 | } 65 | else { 66 | ret = new WaveletTree(seq, wc, bsb, am); 67 | } 68 | return ret; 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /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 | 26 | SequenceBuilderWaveletTreeNoptrs::SequenceBuilderWaveletTreeNoptrs(BitSequenceBuilder * bsb, Mapper * am) { 27 | this->bsb = bsb; 28 | this->am = am; 29 | bsb->use(); 30 | am->use(); 31 | } 32 | 33 | SequenceBuilderWaveletTreeNoptrs::~SequenceBuilderWaveletTreeNoptrs() { 34 | bsb->unuse(); 35 | am->unuse(); 36 | } 37 | 38 | Sequence * SequenceBuilderWaveletTreeNoptrs::build(uint * sequence, size_t len) { 39 | return new WaveletTreeNoptrs(sequence, len, bsb, am); 40 | } 41 | 42 | Sequence * SequenceBuilderWaveletTreeNoptrs::build(const Array & seq) { 43 | return new WaveletTreeNoptrs(seq, bsb, am); 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /src/static/sequence/SequenceBuilderWaveletTreeNoptrsS.cpp: -------------------------------------------------------------------------------- 1 | /* SequenceBuilderWaveletTreeNoptrsS.cpp 2 | * Copyright (C) 2012, 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 | SequenceBuilderWaveletTreeNoptrsS::SequenceBuilderWaveletTreeNoptrsS(BitSequenceBuilder * bsb, Mapper * am) { 26 | this->bsb = bsb; 27 | this->am = am; 28 | bsb->use(); 29 | am->use(); 30 | } 31 | 32 | SequenceBuilderWaveletTreeNoptrsS::~SequenceBuilderWaveletTreeNoptrsS() { 33 | bsb->unuse(); 34 | am->unuse(); 35 | } 36 | 37 | Sequence * SequenceBuilderWaveletTreeNoptrsS::build(uint * sequence, size_t len) { 38 | return new WaveletTreeNoptrsS(sequence, len, bsb, am); 39 | } 40 | 41 | Sequence * SequenceBuilderWaveletTreeNoptrsS::build(const Array & seq) { 42 | return new WaveletTreeNoptrsS(seq, bsb, am); 43 | } 44 | }; 45 | 46 | 47 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/static/sequence/wt_coder_binary.cpp: -------------------------------------------------------------------------------- 1 | /* wt_coder_binary.cpp 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 | #include 23 | 24 | namespace cds_static 25 | { 26 | 27 | wt_coder_binary::wt_coder_binary(const Array & a, Mapper *am) { 28 | //am->use(); 29 | uint maxv = 0; 30 | for(size_t i=0;iunuse(); 34 | } 35 | 36 | wt_coder_binary::wt_coder_binary(uint * seq, size_t n, Mapper * am) { 37 | uint max_v = 0; 38 | for(uint i=0;imap(seq[i]),max_v); 40 | h=bits(max_v); 41 | } 42 | 43 | wt_coder_binary::wt_coder_binary(uchar * seq, size_t n, Mapper * am) { 44 | uint max_v = 0; 45 | for(uint i=0;imap((uint)seq[i]),max_v); 47 | h=bits(max_v); 48 | } 49 | 50 | wt_coder_binary::wt_coder_binary() {} 51 | 52 | wt_coder_binary::~wt_coder_binary() {} 53 | 54 | bool wt_coder_binary::is_set(uint symbol, uint l) const 55 | { 56 | if((1<<(h-l-1))&symbol) return true; 57 | return false; 58 | } 59 | 60 | bool wt_coder_binary::is_set(uint *symbol, uint l) const { 61 | if(bitget(symbol, h - l - 1)) return true; 62 | return false; 63 | } 64 | 65 | uint * wt_coder_binary::get_symbol(uint symbol) const { 66 | uint * ret = new uint[1]; 67 | *ret = symbol; 68 | return ret; 69 | } 70 | 71 | bool wt_coder_binary::done(uint symbol, uint l) const 72 | { 73 | if(l==h) return true; 74 | return false; 75 | } 76 | 77 | size_t wt_coder_binary::getSize() const 78 | { 79 | return sizeof(wt_coder_binary); 80 | } 81 | 82 | void wt_coder_binary::save(ofstream & fp) const 83 | { 84 | uint wr = WT_CODER_BINARY_HDR; 85 | saveValue(fp,wr); 86 | saveValue(fp,h); 87 | } 88 | 89 | wt_coder_binary * wt_coder_binary::load(ifstream & fp) { 90 | uint rd = loadValue(fp); 91 | if(rd!=WT_CODER_BINARY_HDR) return NULL; 92 | wt_coder_binary * ret = new wt_coder_binary(); 93 | ret->h = loadValue(fp); 94 | return ret; 95 | } 96 | }; 97 | -------------------------------------------------------------------------------- /src/static/sequence/wt_node.cpp: -------------------------------------------------------------------------------- 1 | /* wt_node.cpp 2 | * Copyright (C) 2008, Francisco Claude. 3 | * Copyright (C) 2011, Matthias Petri. 4 | * 5 | * wt_node 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 | #include 24 | 25 | namespace cds_static 26 | { 27 | 28 | wt_node * wt_node::load(ifstream & fp) { 29 | uint rd = loadValue(fp); 30 | if(rd==WT_NODE_NULL_HDR) return NULL; 31 | size_t pos = fp.tellg(); 32 | fp.seekg(pos-sizeof(uint)); 33 | switch(rd) { 34 | case WT_NODE_INTERNAL_HDR: return wt_node_internal::load(fp); 35 | case WT_NODE_LEAF_HDR: return wt_node_leaf::load(fp); 36 | } 37 | return NULL; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /src/static/sequence/wt_node_leaf.cpp: -------------------------------------------------------------------------------- 1 | /* wt_node_leaf.cpp 2 | * Copyright (C) 2008, Francisco Claude. 3 | * Copyright (C) 2011, Matthias Petri. 4 | * 5 | * wt_node_leaf 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 | #include 24 | 25 | namespace cds_static 26 | { 27 | 28 | wt_node_leaf::wt_node_leaf(uint symbol, size_t count) { 29 | this->symbol = symbol; 30 | this->count = count; 31 | } 32 | 33 | wt_node_leaf::wt_node_leaf() {} 34 | 35 | wt_node_leaf::~wt_node_leaf() {} 36 | 37 | size_t wt_node_leaf::rank(uint *symbol, size_t pos, uint l, wt_coder *c) const 38 | { 39 | /*if(symbol!=this->symbol) { 40 | return 0; 41 | }*/ 42 | //pos++; 43 | return pos+1; 44 | } 45 | 46 | size_t wt_node_leaf::select(uint *symbol, size_t pos, uint l, wt_coder *c) const 47 | { 48 | //if(symbol!=this->symbol) return (size_t)-1; 49 | if(pos==0 || pos>count) return (size_t)-1; 50 | return pos; 51 | } 52 | 53 | uint wt_node_leaf::access(size_t pos) const 54 | { 55 | return symbol; 56 | } 57 | 58 | uint wt_node_leaf::access(size_t pos, size_t &rank) const 59 | { 60 | rank = pos+1; 61 | return symbol; 62 | } 63 | 64 | pair wt_node_leaf::quantile_freq(size_t left,size_t right,uint q) const 65 | { 66 | return std::make_pair(symbol,right-left+1); 67 | } 68 | 69 | size_t wt_node_leaf::getSize() const 70 | { 71 | return sizeof(wt_node_leaf); 72 | } 73 | 74 | void wt_node_leaf::save(ofstream & fp) const 75 | { 76 | uint wr = WT_NODE_LEAF_HDR; 77 | saveValue(fp,wr); 78 | saveValue(fp,count); 79 | saveValue(fp,symbol); 80 | } 81 | 82 | wt_node_leaf * wt_node_leaf::load(ifstream & fp) { 83 | uint rd = loadValue(fp); 84 | if(rd!=WT_NODE_LEAF_HDR) return NULL; 85 | wt_node_leaf * ret = new wt_node_leaf(); 86 | ret->count = loadValue(fp); 87 | ret->symbol = loadValue(fp); 88 | return ret; 89 | } 90 | }; 91 | -------------------------------------------------------------------------------- /src/utils/cppUtils.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 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 | void tokenize(string str, vector &tokens, char delim) { 17 | string::size_type last_pos = 0; 18 | string::size_type pos = str.find_first_of(delim); 19 | while(pos!=string::npos) { 20 | tokens.push_back(str.substr(last_pos,pos-last_pos)); 21 | last_pos = pos+1; 22 | if(last_pos >= str.length()) break; 23 | pos = str.find_first_of(delim,pos+1); 24 | } 25 | if(last_pos 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 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 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | namespace cds_utils 36 | { 37 | 38 | #ifndef _WIN32 39 | clock_t init; 40 | void start_timing() { 41 | init = clock(); 42 | } 43 | 44 | double get_timing() { 45 | clock_t fin = clock(); 46 | return (1000.*(fin-init)/CLOCKS_PER_SEC); 47 | } 48 | #else 49 | /* FIXME: Put real win32 api calls here. */ 50 | void start_timing() { 51 | } 52 | 53 | double get_timing() { 54 | return 0.0; 55 | } 56 | #endif 57 | }; 58 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # This Makefile is used to build and execute the tests when "make check" 2 | # is run. 3 | 4 | AM_CXXFLAGS = -I../include/ 5 | LDADD = ../src/libcds.la 6 | 7 | check_PROGRAMS = testHuffman testSequence testQuantile testBitSequence testArray toArray2 toArray timeSequence 8 | 9 | testHuffman_SOURCES = testHuffman.cpp 10 | testSequence_SOURCES = testSequence.cpp 11 | testQuantile_SOURCES = testQuantile.cpp 12 | testBitSequence_SOURCES = testBitSequence.cpp 13 | testArray_SOURCES = testArray.cpp 14 | toArray2_SOURCES = toArray2.cpp 15 | toArray_SOURCES = toArray.cpp 16 | timeSequence_SOURCES = timeSequence.cpp 17 | 18 | # FIXME: 19 | # The testBitSequence needs arguments to run. A simple shell wrapper is 20 | # needed for this but not sure what are good testing arguments. Perhaps 21 | # this would work: 22 | # #!/bin/sh 23 | # SEED=`date +%s` 24 | # LENGTH=`expr $SEED % 2048` 25 | # DENSITY=`expr $LENGTH / 2` 26 | # echo .lib/lt-testBitSequence $SEED $LENGTH $DENSITY 27 | # .lib/lt-testBitSequence $SEED $LENGTH $DENSITY 28 | # That still needs some cleanup to make it portable and the exec path is 29 | # probably wrong. 30 | # FIXME: Actually most of the test programs have this problem. Might be 31 | # a better idea to write them to choose default arguments. 32 | TESTS = $(check_PROGRAMS) 33 | 34 | CLEANFILES = bitsequence.tmp 35 | -------------------------------------------------------------------------------- /tests/testArray.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | using namespace cds_utils; 12 | 13 | bool compare(Array * a1, Array * a2) { 14 | if(a1==NULL || a2==NULL) 15 | return a1==a2; 16 | if(a1->getMax() != a2->getMax()) 17 | return false; 18 | if(a1->getLength() != a2->getLength()) 19 | return false; 20 | if(a1->getSize() != a2->getSize()) 21 | return false; 22 | for(size_t i=0;igetLength();i++) 23 | if(a1->getField(i)!=(*a2)[i]) 24 | return false; 25 | return true; 26 | } 27 | 28 | void test(const string & function, Array *a1, Array *a2) { 29 | if(!compare(a1,a2)) { 30 | cout << "Error in ()" << function << endl; 31 | abort(); 32 | } 33 | } 34 | 35 | void testSaveLoad(Array * a) { 36 | string dir = "/tmp/"; 37 | string pfx = "lcds"; 38 | char * fname = tempnam(dir.c_str(),pfx.c_str()); //tmpnam(NULL); 39 | ofstream outfs(fname); 40 | a->save(outfs); 41 | outfs.close(); 42 | ifstream infs(fname); 43 | Array * a_copy = new Array(infs); 44 | infs.close(); 45 | remove(fname); 46 | //delete [] fname; // C function uses malloc 47 | free(fname); 48 | test("testSaveLoad",a,a_copy); 49 | delete a_copy; 50 | } 51 | 52 | void testConstructors(Array * a) { 53 | vector vals_vector; 54 | uint * vals_array = new uint[a->getLength()]; 55 | for(size_t i=0;igetLength();i++) { 56 | vals_vector.push_back(a->getField(i)); 57 | vals_array[i] = a->getField(i); 58 | } 59 | Array * a2 = new Array(vals_vector); 60 | test("testConstructor",a,a2); 61 | delete a2; 62 | a2 = new Array(vals_vector.begin(),vals_vector.end()); 63 | test("testConstructor",a,a2); 64 | delete a2; 65 | a2 = new Array(vals_array,a->getLength()); 66 | test("testConstructor",a,a2); 67 | delete a2; 68 | if(a->getLength()>0) { 69 | a2 = new Array(vals_array,(size_t)0,(size_t)a->getLength()-1,0); 70 | test("testConstructor",a,a2); 71 | delete a2; 72 | } 73 | a2 = new Array(a->getLength(),a->getMax()); 74 | for(size_t i=0;igetLength();i++) 75 | a2->setField(i,a->getField(i)); 76 | test("testConstructor",a,a2); 77 | delete a2; 78 | delete [] vals_array; 79 | } 80 | 81 | Array * buildArray(uint seed, size_t len, uint maxv) { 82 | Array * a = new Array(len,maxv); 83 | srand(seed); 84 | for(size_t i=0;isetField(i,val); 87 | } 88 | return a; 89 | } 90 | 91 | int main(int argc, char ** argv) { 92 | 93 | Array * a; 94 | 95 | // Test 1: empty array 96 | cout << "Testing empty array" << endl; 97 | a = buildArray(57921, 0, 0); 98 | testSaveLoad(a); 99 | testConstructors(a); 100 | delete a; 101 | 102 | // Test 2: binary array 103 | cout << "Testing binary array" << endl; 104 | a = buildArray(57921, 100000, 1); 105 | testSaveLoad(a); 106 | testConstructors(a); 107 | delete a; 108 | 109 | // Test 1: 7 bits array 110 | cout << "Testing 7 bits array" << endl; 111 | a = buildArray(8647, 100000, 126); 112 | testSaveLoad(a); 113 | testConstructors(a); 114 | delete a; 115 | 116 | // Test 1: big array 117 | cout << "Testing big array" << endl; 118 | a = buildArray(8647, 10000000, (1<<23)); 119 | testSaveLoad(a); 120 | testConstructors(a); 121 | delete a; 122 | 123 | cout << endl << "Tests passed!" << endl; 124 | return 0; 125 | } 126 | 127 | -------------------------------------------------------------------------------- /tests/testBitSequence.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | using namespace cds_utils; 13 | using namespace cds_static; 14 | 15 | BitSequence * saveLoad(BitSequence * bs) { 16 | ofstream ofs("bitsequence.tmp"); 17 | bs->save(ofs); 18 | ofs.close(); 19 | ifstream ifs("bitsequence.tmp"); 20 | BitSequence * ret = BitSequence::load(ifs); 21 | ifs.close(); 22 | return ret; 23 | } 24 | 25 | bool testBitSequence(BitString & a, BitSequence * bs) { 26 | size_t rank0SoFar = 0; 27 | size_t rank1SoFar = 0; 28 | for(size_t i=0; iselect1(rank1SoFar)!=i) { 32 | cerr << "SELECT1 ERROR " << i << endl; 33 | return false; 34 | } 35 | if(i>0 && bs->selectNext1(i)!=i) { 36 | cout << "i=" << i << "sn=" << bs->selectNext1(i) << endl; 37 | cerr << "SELECTNEXT1 ERROR" << endl; 38 | return false; 39 | } 40 | } else { 41 | rank0SoFar++; 42 | if(bs->select0(rank0SoFar)!=i) { 43 | cerr << "SELECT0 ERROR" << endl; 44 | return false; 45 | } 46 | if(i>0 && bs->selectNext0(i)!=i) { 47 | cerr << "SELECTNEXT0 ERROR" << endl; 48 | return false; 49 | } 50 | } 51 | if(bs->rank1(i)!=rank1SoFar) 52 | return false; 53 | if(bs->rank0(i)!=rank0SoFar) 54 | return false; 55 | if(bs->access(i)!=a[i]) 56 | return false; 57 | } 58 | return true; 59 | } 60 | 61 | int main(int argc, char ** argv) { 62 | 63 | if(argc!=4) { 64 | cout << "Checks the bitsequence classes generating bitmaps with density using as seed for the numbers generation" << endl << endl; 65 | cout << "usage: " << argv[0] << " " << endl; 66 | return 0; 67 | } 68 | 69 | srand(transform(string(argv[1]))); 70 | uint len = transform(string(argv[2])); 71 | uint dens = transform(string(argv[3])); 72 | 73 | uint act_dens = 0; 74 | BitString a(len); 75 | while(act_dens < dens) { 76 | size_t pos = rand()%len; 77 | if(!a[pos]) { 78 | act_dens++; 79 | a.setBit(pos,true); 80 | } 81 | } 82 | 83 | BitSequenceRG bsRG(a,20); 84 | BitSequence * s = saveLoad(&bsRG); 85 | if(!testBitSequence(a,s)) { 86 | cerr << "ERROR TESTING BitSequenceRG" << endl; 87 | return -1; 88 | } 89 | cout << "RG OK\n" << endl; 90 | delete (BitSequenceRG *)s; 91 | 92 | BitSequenceDArray bsDArray(a); 93 | s = saveLoad(&bsDArray); 94 | if(!testBitSequence(a,s)) { 95 | cerr << "ERROR TESTING BitSequenceDArray" << endl; 96 | return -1; 97 | } 98 | cout << "DArray OK\n" << endl; 99 | delete (BitSequenceDArray *)s; 100 | 101 | BitSequenceSDArray bsSDArray(a); 102 | s = saveLoad(&bsSDArray); 103 | if(!testBitSequence(a,s)) { 104 | cerr << "ERROR TESTING BitSequenceSDArray" << endl; 105 | return -1; 106 | } 107 | cout << "SDArray OK\n" << endl; 108 | delete (BitSequenceSDArray *)s; 109 | 110 | BitSequenceRRR bsRRR(a,33); 111 | s = saveLoad(&bsRRR); 112 | if(!testBitSequence(a,s)) { 113 | cerr << "ERROR TESTING BitSequenceRRR" << endl; 114 | return -1; 115 | } 116 | cout << "RRR OK\n" << endl; 117 | delete (BitSequenceRRR *)s; 118 | return 0; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /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 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | using namespace cds_static; 11 | 12 | 13 | void testSequence(Array & a, Sequence & bs) { 14 | ofstream outfs("sequence.tmp"); 15 | bs.save(outfs); 16 | outfs.close(); 17 | ifstream infs("sequence.tmp"); 18 | Sequence * seq = Sequence::load(infs); 19 | infs.close(); 20 | uint maxv = a.getMax(); 21 | size_t *count = new size_t[maxv+1]; 22 | for(size_t i=0;i<=maxv;i++) 23 | count[i] = 0; 24 | for(size_t i=0;iaccess(i)) { 27 | cerr << "ERROR ACCESS" << endl; 28 | cerr << "Got:" << seq->access(i) << " Expected:" << a[i] << endl; 29 | exit(-3); 30 | } 31 | for(uint j=a[i];j<=a[i];j++) { 32 | if(seq->rank(j,i)!=count[j]) { 33 | cerr << "ERROR RANK " << endl; 34 | cerr << " Rank result: " << bs.rank(j,i) << " count=" << count[j] << endl; 35 | cerr << " symbol=" << j << " position=" << i << endl; 36 | exit(-1); 37 | } 38 | } 39 | if(seq->select(a[i],count[a[i]])!=i) { 40 | cerr << "ERROR SELECT " << endl; 41 | cerr << "a[i]=" << a[i] << " maxv=" << maxv << endl; 42 | cerr << "bs.select=" << bs.select(a[i],count[a[i]]) << " i=" << i << endl; 43 | exit(-2); 44 | } 45 | 46 | } 47 | delete []count; 48 | delete seq; 49 | } 50 | 51 | int main(int argc, char ** argv) { 52 | 53 | if(argc!=4) { 54 | cout << "Checks the array class generating elements between 0 and using as seed for the numbers generation" << endl << endl; 55 | cout << "usage: " << argv[0] << " " << endl; 56 | return 0; 57 | } 58 | 59 | srand(transform(string(argv[1]))); 60 | uint len = transform(string(argv[2])); 61 | uint maxv = transform(string(argv[3])); 62 | 63 | //cout << "maxv = " << maxv << endl; 64 | //cout << "len = " << len << endl; 65 | 66 | Array a(len,maxv); 67 | for(uint i=0;iuse(); 77 | mapper2->use(); 78 | cout << "Test 1 : Wavelet tree with pointers" << endl; 79 | // WaveletTree wt1(a,new wt_coder_binary(a, mapper),new BitSequenceBuilderRRR(32), mapper); 80 | WaveletTreeNoptrs wt1(a, new BitSequenceBuilderRRR(32), mapper); 81 | cout << "bs.size() = " << wt1.getSize() << endl; 82 | testSequence(a, wt1); 83 | 84 | cout << "Test 2 : Wavelet tree without pointers" << endl; 85 | // uint *tmp = new uint[a.getLength()]; 86 | // for (uint i=0; i < a.getLength(); i++) 87 | // tmp[i] = a.getField(i); 88 | // WaveletMatrix wt3(tmp, a.getLength(), new BitSequenceBuilderRRR(32), mapper); 89 | WaveletMatrix wt3(a, new BitSequenceBuilderRRR(32), mapper); 90 | // WaveletTreeNoptrs wt3(tmp, a.getLength(), new BitSequenceBuilderRRR(32), mapper); 91 | cout << "bs.size() = " << wt3.getSize() << endl; 92 | testSequence(a, wt3); 93 | mapper->unuse(); 94 | mapper2->unuse(); 95 | return 0; 96 | } 97 | 98 | -------------------------------------------------------------------------------- /tests/toArray.cpp: -------------------------------------------------------------------------------- 1 | /* toArray.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 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | #include 36 | #include 37 | 38 | using namespace cds_utils; 39 | 40 | int main(int argc, char ** argv) { 41 | if(argc!=3) { 42 | cout << "usage: " << argv[0] << " " << endl; 43 | return 0; 44 | } 45 | 46 | size_t len = 0; 47 | uchar * content = loadValue(argv[1],len); 48 | uint * content2 = new uint[len]; 49 | 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 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | #include 36 | #include 37 | 38 | using namespace cds_utils; 39 | 40 | int main(int argc, char ** argv) { 41 | if(argc!=3) { 42 | cout << "usage: " << argv[0] << " " << endl; 43 | return 0; 44 | } 45 | 46 | size_t len = 0; 47 | int * content = loadValue(argv[1],len); 48 | uint * content2 = new uint[len]; 49 | size_t pos = 0; 50 | for(size_t i=3;i0) content2[pos++]=content[i]; 52 | 53 | Array a(content2,pos); 54 | ofstream out(argv[2]); 55 | a.save(out); 56 | out.close(); 57 | 58 | delete [] content; 59 | delete [] content2; 60 | return 0; 61 | } 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /tutorial/src/ArrayExample.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ArrayExample.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | using namespace cds_utils; 27 | 28 | int main(int argc, char **argv) { 29 | size_t N=0; 30 | cout << "Enter array length: "; 31 | cin >> N; 32 | uint * A = new uint[N]; 33 | for(size_t i=0;i> A[i]; 36 | } 37 | 38 | Array * a = new Array(A,N); 39 | delete [] A; 40 | 41 | cout << "Size: " << a->getSize() << " bytes" << endl; 42 | for(uint i=0;i> N; 33 | cout << "Enter the maximum value to be stored: "; 34 | cin >> M; 35 | Array *a = new Array(N,M); 36 | for(size_t i=0;i> tmp; 40 | a->setField(i,tmp); 41 | } 42 | 43 | cout << "Size: " << a->getSize() << " bytes" << endl; 44 | for(uint i=0;i> N; 33 | uint * bs = new uint[uint_len(N,1)]; 34 | for(uint i=0;i> b; 38 | if(b==0) bitclean(bs,i); 39 | else cds_utils::bitset(bs,i); 40 | } 41 | BitSequenceRG * bsrg = new BitSequenceRG(bs,N,20); 42 | cout << "rank(" << N/2 << ")=" << bsrg->rank1(N/2) << endl; 43 | cout << "select(1) = " << bsrg->select1(1) << endl; 44 | cout << "size = " << bsrg->getSize() << endl; 45 | delete bsrg; 46 | delete [] bs; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /tutorial/src/BitSequenceRRRExample.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * BitSequenceRRRExample.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | using namespace cds_utils; 27 | using namespace cds_static; 28 | 29 | int main(int argc, char **argv) { 30 | size_t N; 31 | cout << "Length of the bitmap: "; 32 | cin >> N; 33 | uint * bs = new uint[uint_len(N,1)]; 34 | for(uint i=0;i> b; 38 | if(b==0) bitclean(bs,i); 39 | else cds_utils::bitset(bs,i); 40 | } 41 | BitSequenceRRR * bsrrr = new BitSequenceRRR(bs,N,16); 42 | cout << "rank(" << N/2 << ")=" << bsrrr->rank1(N/2) << endl; 43 | cout << "select(1) = " << bsrrr->select1(1) << endl; 44 | cout << "size = " << bsrrr->getSize() << endl; 45 | delete bsrrr; 46 | delete [] bs; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /tutorial/src/BitSequenceSDArrayExample.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * BitSequenceSDArrayExample.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | using namespace cds_utils; 28 | using namespace cds_static; 29 | 30 | int main(int argc, char **argv) { 31 | size_t N; 32 | cout << "Length of the bitmap: "; 33 | cin >> N; 34 | uint * bs = new uint[uint_len(N,1)]; 35 | for(uint i=0;i> b; 39 | if(b==0) bitclean(bs,i); 40 | else cds_utils::bitset(bs,i); 41 | } 42 | BitSequenceSDArray * bss = new BitSequenceSDArray(bs,N); 43 | cout << "rank(" << N/2 << ")=" << bss->rank1(N/2) << endl; 44 | cout << "select(1) = " << bss->select1(1) << endl; 45 | cout << "size = " << bss->getSize() << endl; 46 | delete bss; 47 | delete [] bs; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /tutorial/src/Makefile.am: -------------------------------------------------------------------------------- 1 | # Build the tutorial programs. 2 | 3 | AM_CXXFLAGS = -I../../include/ 4 | LDADD = ../../src/libcds.la 5 | noinst_PROGRAMS = ArrayExample2 ArrayExample BitSequenceRGExample BitSequenceRRRExample BitSequenceSDArrayExample SequenceAlphPartExample SequenceGMRExample SequenceWaveletTreeExample 6 | 7 | ArrayExample2_SOURCES = ArrayExample2.cpp 8 | ArrayExample_SOURCES = ArrayExample.cpp 9 | BitSequenceRGExample_SOURCES = BitSequenceRGExample.cpp 10 | BitSequenceRRRExample_SOURCES = BitSequenceRRRExample.cpp 11 | BitSequenceSDArrayExample_SOURCES = BitSequenceSDArrayExample.cpp 12 | SequenceAlphPartExample_SOURCES = SequenceAlphPartExample.cpp 13 | SequenceGMRExample_SOURCES = SequenceGMRExample.cpp 14 | SequenceWaveletTreeExample_SOURCES = SequenceWaveletTreeExample.cpp 15 | -------------------------------------------------------------------------------- /tutorial/src/SequenceAlphPartExample.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * SequenceAlphPartExample.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | using namespace cds_static; 27 | 28 | int main(int argc, char **argv) { 29 | 30 | size_t N; 31 | uint s; 32 | cout << "Length: "; 33 | cin >> N; 34 | uint * seq = new uint[N]; 35 | for(size_t i=0;i> seq[i]; 39 | } 40 | 41 | SequenceBuilder * sb1 = new SequenceBuilderWaveletTree( 42 | new BitSequenceBuilderRG(20), 43 | new MapperNone()); 44 | SequenceBuilder * sb2 = new SequenceBuilderGMRChunk( 45 | new BitSequenceBuilderRG(20), 46 | new PermutationBuilderMRRR( 47 | 20, new BitSequenceBuilderRG(20))); 48 | SequenceBuilder * sb3 = new SequenceBuilderGMR( 49 | new BitSequenceBuilderRG(20), 50 | sb2); 51 | 52 | SequenceAlphPart * ap = new SequenceAlphPart(seq, N, 0u, 53 | sb1, sb3); 54 | cout << "size = " << ap->getSize() << " bytes" << endl; 55 | 56 | delete ap; 57 | delete []seq; 58 | return 0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /tutorial/src/SequenceGMRExample.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * SequenceGMRExample.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | using namespace cds_static; 27 | 28 | int main(int argc, char **argv) { 29 | 30 | size_t N; 31 | uint s; 32 | cout << "Length: "; 33 | cin >> N; 34 | uint * seq = new uint[N]; 35 | for(size_t i=0;i> seq[i]; 39 | } 40 | SequenceGMR * gmr = new SequenceGMR(seq, N, 5u, 41 | new BitSequenceBuilderRG(20), 42 | new SequenceBuilderGMRChunk( 43 | new BitSequenceBuilderRG(20), 44 | new PermutationBuilderMRRR( 45 | 20, 46 | new BitSequenceBuilderRG(20)))); 47 | cout << "size = " << gmr->getSize() << " bytes" << endl; 48 | 49 | delete gmr; 50 | delete []seq; 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tutorial/src/SequenceWaveletTreeExample.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * SequenceWaveletTreeExample.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | using namespace cds_static; 27 | 28 | int main(int argc, char **argv) { 29 | 30 | size_t N; 31 | uint s; 32 | cout << "Length: "; 33 | cin >> N; 34 | uint * seq = new uint[N]; 35 | for(size_t i=0;i> seq[i]; 39 | } 40 | WaveletTree * wt1 = new WaveletTree(seq, N, 41 | new wt_coder_huff(seq, N, 42 | new MapperNone()), 43 | new BitSequenceBuilderRG(20), 44 | new MapperNone()); 45 | cout << "size = " << wt1->getSize() << " bytes" << endl; 46 | 47 | delete wt1; 48 | delete []seq; 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /tutorial/ssa/Makefile.am: -------------------------------------------------------------------------------- 1 | # Build the ssa tutorial programs. 2 | 3 | AM_CXXFLAGS = -I../../include/ 4 | LDADD = ../../src/libcds.la 5 | noinst_PROGRAMS = test_count build_index dump_bwt 6 | 7 | test_count_SOURCES = test_count.cpp ssa.cpp 8 | 9 | dump_bwt_SOURCES = dump_bwt.cpp ssa.cpp 10 | 11 | build_index_SOURCES = build_index.cpp ssa.cpp 12 | 13 | -------------------------------------------------------------------------------- /tutorial/ssa/build_index.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * build_index.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "ssa.h" 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | int main(int argc, char ** argv) { 28 | if(argc!=3) { 29 | cout << "usage: " << argv[0] << " " << endl; 30 | return 0; 31 | } 32 | 33 | fstream input(argv[1],ios::in | ios::binary); 34 | if(!input.is_open()) { 35 | cout << "Error opening file: " << argv[1] << endl; 36 | return -1; 37 | } 38 | 39 | input.seekg(0,ios::end); 40 | uint n=input.tellg(); 41 | uchar * text = new uchar[n+1]; 42 | 43 | input.seekg(0,ios::beg); 44 | input.read((char*)text,sizeof(uchar)*n); 45 | input.close(); 46 | //for(uint i=0;iset_samplepos(32); 51 | _ssa->set_samplesuff(32); 52 | _ssa->build_index(); 53 | _ssa->print_stats(); 54 | 55 | cout << "Index size: " << _ssa->size() << endl; 56 | 57 | ofstream fp(argv[2]); 58 | _ssa->save(fp); 59 | fp.close(); 60 | 61 | //delete sbb; 62 | delete _ssa; 63 | delete [] text; 64 | 65 | return 0; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /tutorial/ssa/dump_bwt.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * dump_bwt.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "ssa.h" 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | int main(int argc, char ** argv) { 28 | if(argc!=2) { 29 | cout << "usage: " << argv[0] << " " << endl; 30 | return 0; 31 | } 32 | 33 | ifstream ssainput(argv[1]); 34 | ssa * _ssa = new ssa(ssainput); 35 | ssainput.close(); 36 | _ssa->print_bwt(); 37 | delete _ssa; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /tutorial/ssa/ssa.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ssa.h 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #ifndef SSA_WORDS_H 21 | #define SSA_WORDS_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | using namespace std; 32 | using namespace cds_static; 33 | 34 | #define SSA_HDR 29 35 | 36 | class ssa 37 | { 38 | public: 39 | ssa(uchar * seq, uint n, bool free_text=false); 40 | ssa(ifstream & fp); 41 | ~ssa(); 42 | 43 | bool set_samplepos(uint sample); 44 | bool set_samplesuff(uint sample); 45 | 46 | bool build_index(Array * a=NULL, BitSequence * b=NULL); 47 | 48 | uint size(); 49 | void print_stats(); 50 | uint length(); 51 | 52 | uint locate(uchar * pattern, uint m, uint ** occ); 53 | uint count(uchar * pattern, uint m); 54 | uchar * extract(uint i, uint j); 55 | uchar extract_pos(uint i); 56 | 57 | void print_bwt(); 58 | 59 | uchar * rebuild(); 60 | void save(ofstream & fp); 61 | 62 | 63 | protected: 64 | uint n,n1; 65 | uint sigma; 66 | Sequence * bwt; 67 | BitSequence * sampled; 68 | uint samplepos; 69 | uint samplesuff; 70 | uint * pos_sample; 71 | uint * suff_sample; 72 | uchar * sbuff; 73 | uint spos; 74 | uint * occ; 75 | uint maxV; 76 | 77 | bool built; 78 | bool free_text; 79 | uchar * _seq; 80 | uint * _bwt; 81 | uint * _sa; 82 | 83 | void build_bwt(); 84 | void build_sa(); 85 | void sort_sa(uint ini, uint fin); 86 | int cmp(uint i, uint j); 87 | void swap(uint i, uint j); 88 | uint pivot(uint ini, uint fin, uint piv); 89 | void fill_buffer(uint i, uint j); 90 | 91 | }; 92 | #endif 93 | -------------------------------------------------------------------------------- /tutorial/ssa/test_count.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * test_count.cpp 3 | * Copyright (C) 2011 Francisco Claude F. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "ssa.h" 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | uint brute_check(uchar * text, uint n, uchar * pattern, uint m) { 28 | uint ret = 0; 29 | for(uint i=0;i " << endl; 43 | return 0; 44 | } 45 | 46 | fstream input(argv[1],ios::in | ios::binary); 47 | if(!input.is_open()) { 48 | cout << "Error opening file: " << argv[1] << endl; 49 | return -1; 50 | } 51 | 52 | input.seekg(0,ios::end); 53 | uint n=input.tellg(); 54 | uchar * text = new uchar[n+1]; 55 | 56 | input.seekg(0,ios::beg); 57 | input.read((char*)text,sizeof(uchar)*n); 58 | input.close(); 59 | //for(uint i=0;iprint_stats(); 66 | 67 | uint m; 68 | { 69 | stringstream ss; 70 | ss << argv[3]; 71 | ss >> m; 72 | } 73 | 74 | uint rep; 75 | { 76 | stringstream ss; 77 | ss << argv[4]; 78 | ss >> rep; 79 | } 80 | 81 | uint total_occ = 0; 82 | uchar * pattern = new uchar[m+1]; 83 | for(uint i=0;icount(pattern,m); 89 | uint real_occ = brute_check(text,n,pattern,m); 90 | if(occ!=real_occ) { 91 | cout << "Error for pattern " << i+1 << endl; 92 | cout << "ssa->count() returned " << occ << endl; 93 | cout << "expected value is " << real_occ << endl; 94 | break; 95 | } 96 | total_occ += occ; 97 | } 98 | 99 | cout << "Total occ: " << total_occ << endl; 100 | 101 | delete [] pattern; 102 | delete _ssa; 103 | delete [] text; 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /tutorial/tutorial.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fclaude/libcds/c3002bef485ac00ed42e544c1aa2699b4d8c9311/tutorial/tutorial.pdf --------------------------------------------------------------------------------