dict-0.h
Go to the documentation of this file.
1 //File: $Id$
2 // Author: John Wu <John.Wu at ACM.org>
3 // Copyright (c) 2000-2016 the Regents of the University of California
4 #ifndef IBIS_DICTIONARY_H
5 #define IBIS_DICTIONARY_H
6 #include "util.h"
9 #include "array_t.h"
10 
19 class FASTBIT_CXX_DLLSPEC ibis::dictionary {
20 public:
21  ~dictionary() {clear();}
22  dictionary(const dictionary& dic);
24  dictionary() : raw_(1) {raw_[0] = 0;}
25 
27  uint32_t size() const {return key_.size();}
28 
29  const char* operator[](uint32_t i) const;
30  uint32_t operator[](const char* str) const;
31  const char* find(const char* str) const;
32  void patternSearch(const char* pat, array_t<uint32_t>& matches) const;
33 
34  uint32_t insert(const char* str);
35  uint32_t insertRaw(char* str);
36  uint32_t appendOrdered(const char* str);
37 
38  void clear();
39  void swap(dictionary&);
40 
41  int read(const char* name);
42  int write(const char* name) const;
43 
44  void sort(array_t<uint32_t>&);
45  int merge(const dictionary&);
46  int morph(const dictionary&, array_t<uint32_t>&) const;
47 
48  bool equal_to(const ibis::dictionary&) const;
49 
50  void copy(const dictionary& rhs);
51 
52 protected:
53 
65 
66  int readRaw(const char*, FILE *);
67  int readKeys(const char*, FILE *);
68 
69 private:
70  dictionary& operator=(const dictionary&);
71 }; // ibis::dictionary
72 
75  raw_.swap(rhs.raw_);
76  key_.swap(rhs.key_);
77  code_.swap(rhs.code_);
78  buffer_.swap(rhs.buffer_);
79 } // ibis::dictionary::swap
80 
84 inline const char* ibis::dictionary::operator[](uint32_t i) const {
85  return (i < raw_.size() ? raw_[i] : raw_[0]);
86 } // int to string
87 
92 inline const char* ibis::dictionary::find(const char* str) const {
93  const char* ret = 0;
94  const uint32_t ind = operator[](str);
95  if (ind < raw_.size())
96  ret = raw_[ind];
97  return ret;
98 } // ibis::dictionary::find
99 #endif // IBIS_DICTIONARY_H
void clear()
Clear the allocated memory. Leave only the NULL entry.
Definition: dict-0.cpp:363
const char * find(const char *str) const
Find the given string in the dictionary.
Definition: dict-0.h:92
void sort(array_t< uint32_t > &)
Reassign the integer values to the strings.
Definition: dict-0.cpp:816
int readKeys(const char *, FILE *)
Read the ordered strings.
Definition: dict-0.cpp:314
array_t< uint32_t > code_
Member variable code_ contains the integer code for each string in key_.
Definition: dict-0.h:61
const char * operator[](uint32_t i) const
Return a string corresponding to the integer.
Definition: dict-0.h:84
int morph(const dictionary &, array_t< uint32_t > &) const
Produce an array that maps the integers in old dictionary to the new one.
Definition: dict-0.cpp:920
void swap(array_t< T > &rhs)
Swap the content of two array_t objects.
Definition: array_t.h:184
The current implementation of FastBit is code named IBIS; most data structures and functions are in t...
Definition: bord.h:16
uint32_t insertRaw(char *str)
Non-copying insert.
Definition: dict-0.cpp:730
int read(const char *name)
Read the content of the named file.
Definition: dict-0.cpp:173
void copy(const dictionary &rhs)
Copy function. Use copy constructor and swap the content.
Definition: dict-0.cpp:60
int merge(const dictionary &)
Merge the incoming dictionary with this one.
Definition: dict-0.cpp:834
array_t< const char * > key_
Member variable key_ contains the string values in alphabetic order.
Definition: dict-0.h:58
uint32_t insert(const char *str)
Insert a string to the dictionary.
Definition: dict-0.cpp:578
uint32_t size() const
Return the number of valid (not null) strings in the dictionary.
Definition: dict-0.h:27
Defines minor utility functions and common classes used by FastBit.
int write(const char *name) const
Write the content of the dictionary to the named file.
Definition: dict-0.cpp:81
dictionary()
Default constructor. Generates one (NULL) entry.
Definition: dict-0.h:24
array_t< const char * > raw_
Member variable raw_ contains the string values in the order of the code assignment.
Definition: dict-0.h:56
void swap(dictionary &)
Swap the content of two dictionaries.
Definition: dict-0.h:74
array_t< char * > buffer_
Member varaible buffer_ contains a list of pointers to the memory that holds the strings.
Definition: dict-0.h:64
bool equal_to(const ibis::dictionary &) const
Compare whether this dicrionary and the other are equal in content.
Definition: dict-0.cpp:48
Provide a dual-directional mapping between strings and integers.
Definition: dict-0.h:19
uint32_t appendOrdered(const char *str)
Append a string to the dictionary.
Definition: dict-0.cpp:686
int readRaw(const char *, FILE *)
Read the raw strings.
Definition: dict-0.cpp:251
void patternSearch(const char *pat, array_t< uint32_t > &matches) const
Find all codes that matches the SQL LIKE pattern.
Definition: dict-0.cpp:375

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