SIS
Symmetric Index Structures
|
00001 #ifndef VOIDSEQUENCEADAPTER_CPP 00002 #define VOIDSEQUENCEADAPTER_CPP 00003 00004 #include "VoidSequenceAdapter.hpp" 00005 00006 namespace lmu { namespace cis { namespace sis { 00007 00008 std::ifstream& operator>>(std::ifstream& in, VoidSequenceAdapter& seq) { 00009 if (DEBUG_LEVEL > 5) std::cerr << "std::ifstream& operator>>(std::ifstream& in, VoidSequenceAdapter& seq)" << std::endl; 00010 00011 std::string tmp; 00012 in >> tmp; 00013 00014 seq.clear(); 00015 seq.Add(tmp.c_str()); 00016 00017 return in; 00018 } 00019 00020 void VoidSequenceAdapter::Add(const void* elementToAdd) { 00021 VoidSequenceAdd( C_VoidSequence, elementToAdd ); 00022 } 00023 00024 void VoidSequenceAdapter::Set( UINT position, const void * element ) { 00025 VoidSequenceSet( C_VoidSequence, position, element ); 00026 } 00027 00028 void VoidSequenceAdapter::Write( FILE * fp, UINT * sizes, UINT numberOfSizes ) { 00029 VoidSequenceWrite( C_VoidSequence, fp, sizes, numberOfSizes ); 00030 } 00031 00032 VoidSequence * VoidSequenceAdapter::Read( FILE * fp ) { 00033 C_VoidSequence = VoidSequenceRead( fp ); 00034 return C_VoidSequence; 00035 } 00036 00037 VoidSequence * VoidSequenceAdapter::Read( const S8* fn ) { 00038 FILE* fpIn = Fopen(fn, "rb"); 00039 C_VoidSequence = VoidSequenceRead( fpIn ); 00040 Fclose(fpIn); 00041 return C_VoidSequence; 00042 } 00043 00044 void VoidSequenceAdapter::Shrink() { 00045 VoidSequenceShrink( C_VoidSequence ); 00046 } 00047 00048 void VoidSequenceAdapter::Append( const VoidSequence * s ) { 00049 VoidSequenceAppend( C_VoidSequence, s ); 00050 } 00051 00052 void VoidSequenceAdapter::Append( const VoidSequenceAdapter& s ) { 00053 VoidSequenceAppend( C_VoidSequence, s.get() ); 00054 } 00055 00056 void VoidSequenceAdapter::Cpy( VoidSequence * dest, const VoidSequence * src ) { 00057 VoidSequenceCpy( C_VoidSequence, src ); 00058 } 00059 00060 VoidSequence* VoidSequenceAdapter::get() const { 00061 return C_VoidSequence; 00062 } 00063 00064 VoidSequence* VoidSequenceAdapter::dollarize(VoidSequence * line) { 00065 if (DEBUG_LEVEL > 5) std::cerr << "VoidSequence* VoidSequenceAdapter::dollarize(VoidSequence * line)" << std::endl; 00066 VoidSequence * sharpDocumentDollar; // = nullptr; 00067 00068 mSymbolAndVariables( zero ) 00069 mSymbolAndVariables( one ) 00070 00071 mValidateBitsPerSymbol( bitsPerSymbol_ ) 00072 symbolSize_ = bitsPerSymbol_/8; 00073 mSymbolAssignValue( zero, 0, symbolSize_ ) 00074 mSymbolAssignValue( one, 1, symbolSize_ ) 00075 00076 sharpDocumentDollar = VoidSequenceInit2( symbolSize_, line->seqStored + 2, 1 ); 00077 00078 VoidSequenceAdd( sharpDocumentDollar, one ); 00079 VoidSequenceAppend( sharpDocumentDollar, line ); 00080 VoidSequenceAdd( sharpDocumentDollar, zero ); 00081 00082 return sharpDocumentDollar; 00083 } 00084 00085 VoidSequenceAdapter& VoidSequenceAdapter::dollarizer() { 00086 if (DEBUG_LEVEL > 5) std::cerr << "VoidSequenceAdapter& VoidSequenceAdapter::dollarizer()" << std::endl; 00087 C_VoidSequence = dollarize(); 00088 return *this; 00089 } 00090 00091 VoidSequence* VoidSequenceAdapter::dollarize() const { 00092 if (DEBUG_LEVEL > 5) std::cerr << "VoidSequence* VoidSequenceAdapter::dollarize() const" << std::endl; 00093 VoidSequence * line = C_VoidSequence; 00094 VoidSequence * sharpDocumentDollar; // = nullptr; 00095 00096 mSymbolAndVariables( zero ) 00097 mSymbolAndVariables( one ) 00098 00099 mValidateBitsPerSymbol( bitsPerSymbol_ ) 00100 00101 assert(symbolSize_ == bitsPerSymbol_/8); 00102 00103 mSymbolAssignValue( zero, 0, symbolSize_ ) 00104 mSymbolAssignValue( one, 1, symbolSize_ ) 00105 00106 sharpDocumentDollar = VoidSequenceInit2( symbolSize_, line->seqStored + 2, 1 ); 00107 00108 VoidSequenceAdd( sharpDocumentDollar, one ); 00109 VoidSequenceAppend( sharpDocumentDollar, line ); 00110 VoidSequenceAdd( sharpDocumentDollar, zero ); 00111 00112 return sharpDocumentDollar; 00113 } 00114 00115 void VoidSequenceAdapter::Add(const S8* input) { 00116 if (DEBUG_LEVEL > 5) std::cerr << "virtual void VoidSequenceAdapter::Add(const S8* input)" << std::endl; 00117 00118 for (const S8 * p = input ; *p ; p++) { 00119 VoidSequenceAdd(C_VoidSequence, static_cast<const void*>(p)); 00120 } 00121 } 00122 00123 const S8* VoidSequenceAdapter::print() const { 00124 return (const S8*)(C_VoidSequence); 00125 } 00126 00127 void VoidSequenceAdapter::clear() { 00128 VoidSequenceFree(this->get()); // Call structs own free on the pointer we are keeping as an adapter class. 00129 } 00130 00131 void* VoidSequenceAdapter::at(UINT position) { 00132 return (C_VoidSequence->seq + ((position)*((C_VoidSequence)->elementSize))); 00133 } 00134 00135 UINT VoidSequenceAdapter::length() { 00136 return C_VoidSequence->seqStored; 00137 } 00138 00139 }}} /* End of namespace lmu::cis::sis */ 00140 00141 #endif /* end of include guard: VOIDSEQUENCEADAPTER_CPP */