dictionary.h
Go to the documentation of this file.
00001 //File: $Id$
00002 // Author: John Wu <John.Wu at ACM.org>
00003 // Copyright 2000-2012 the Regents of the University of California
00004 #ifndef IBIS_DICTIONARY_H
00005 #define IBIS_DICTIONARY_H
00006 
00007 
00008 #include "util.h"
00009 #include "array_t.h"
00010 
00019 class FASTBIT_CXX_DLLSPEC ibis::dictionary {
00020 public:
00021     ~dictionary() {clear();}
00022     dictionary(const dictionary& dic);
00024     dictionary() : raw_(1) {raw_[0] = 0;}
00025 
00027     uint32_t size() const {return key_.size();}
00028 
00029     const char* operator[](uint32_t i) const;
00030     uint32_t operator[](const char* str) const;
00031     const char* find(const char* str) const;
00032     void patternSearch(const char* pat, array_t<uint32_t>& matches) const;
00033 
00034     uint32_t insert(const char* str);
00035     uint32_t insertRaw(char* str);
00036 
00037     void clear();
00038     void swap(dictionary&);
00039 
00040     int  read(const char* name);
00041     int  write(const char* name) const;
00042 
00043     void sort(array_t<uint32_t>&);
00044     int  merge(const dictionary&);
00045     int  morph(const dictionary&, array_t<uint32_t>&) const;
00046 
00047     bool equal_to(const ibis::dictionary&) const;
00048 
00049     void copy(const dictionary& rhs);
00050 
00051 protected:
00052 
00055     array_t<const char*> raw_;
00057     array_t<const char*> key_;
00060     array_t<uint32_t> code_;
00063     array_t<char*> buffer_;
00064 
00065     int readRaw(const char*, FILE *);
00066     int readKeys(const char*, FILE *);
00067 
00068 private:
00069     dictionary& operator=(const dictionary&);
00070 }; // ibis::dictionary
00071 
00073 inline void ibis::dictionary::swap(ibis::dictionary& rhs) {
00074     raw_.swap(rhs.raw_);
00075     key_.swap(rhs.key_);
00076     code_.swap(rhs.code_);
00077     buffer_.swap(rhs.buffer_);
00078 } // ibis::dictionary::swap
00079 
00083 inline const char* ibis::dictionary::operator[](uint32_t i) const {
00084     return (i < raw_.size() ? raw_[i] : raw_[0]);
00085 } // int to string
00086 
00091 inline const char* ibis::dictionary::find(const char* str) const {
00092     const char* ret = 0;
00093     const uint32_t ind = operator[](str);
00094     if (ind < raw_.size())
00095         ret = raw_[ind];
00096     return ret;
00097 } // ibis::dictionary::find
00098 #endif // IBIS_DICTIONARY_H

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive