utilidor.h
Go to the documentation of this file.
1 // File: $Id$
2 // Author: John Wu <John.Wu at ACM.org>
3 // Copyright (c) 2008-2016 the Regents of the University of California
4 #ifndef IBIS_UTILIDOR_H
5 #define IBIS_UTILIDOR_H
6 
19 #include <algorithm>
20 #include "array_t.h" // array_t
21 
22 namespace ibis {
23  typedef array_t< rid_t > RIDSet; // RIDSet
24 
25  namespace util {
26 
30  void FASTBIT_CXX_DLLSPEC sortRIDs(ibis::RIDSet&);
32  void FASTBIT_CXX_DLLSPEC sortRIDsq(ibis::RIDSet&, uint32_t, uint32_t);
34  void FASTBIT_CXX_DLLSPEC sortRIDsi(ibis::RIDSet&, uint32_t, uint32_t);
36 
38  template <typename T>
39  void FASTBIT_CXX_DLLSPEC
40  reorder(array_t<T> &arr, const array_t<uint32_t> &ind);
41  void FASTBIT_CXX_DLLSPEC
42  reorder(std::vector<std::string> &arr, const array_t<uint32_t> &ind);
44  template <typename T>
45  void FASTBIT_CXX_DLLSPEC
46  reorder(array_t<T*> &arr, const array_t<uint32_t> &ind);
50  template <typename T1, typename T2>
51  void FASTBIT_CXX_DLLSPEC
52  sortAll(array_t<T1>& arr1, array_t<T2>& arr2);
53 
55  int64_t FASTBIT_CXX_DLLSPEC
56  sortMerge(std::vector<std::string>& valR, array_t<uint32_t>& indR,
57  std::vector<std::string>& valS, array_t<uint32_t>& indS);
60  template <typename T> int64_t FASTBIT_CXX_DLLSPEC
61  sortMerge(array_t<T>& valR, array_t<uint32_t>& indR,
62  array_t<T>& valS, array_t<uint32_t>& indS);
66  template <typename T> int64_t FASTBIT_CXX_DLLSPEC
67  sortMerge(array_t<T>& valR, array_t<uint32_t>& indR,
68  array_t<T>& valS, array_t<uint32_t>& indS,
69  double delta1, double delta2);
70 
73  template <typename T1, typename T2>
74  void FASTBIT_CXX_DLLSPEC
75  sortKeys(array_t<T1>& keys, array_t<T2>& vals);
77  void FASTBIT_CXX_DLLSPEC
78  sortStrings(std::vector<std::string>& keys, array_t<uint32_t>& vals);
80  void FASTBIT_CXX_DLLSPEC
81  sortStrings(std::vector<std::string>& keys, array_t<uint32_t>& vals,
82  uint32_t begin, uint32_t end);
84  void FASTBIT_CXX_DLLSPEC
85  sortStrings(array_t<const char*>& keys, array_t<uint32_t>& vals);
87  void FASTBIT_CXX_DLLSPEC
88  sortStrings(array_t<const char*>& keys, array_t<uint32_t>& vals,
89  uint32_t begin, uint32_t end);
90 
91  template <typename T> size_t
92  find(const std::vector<T>&, const T&, size_t);
93  template <typename T> size_t
94  find(const array_t<T>&, const T&, size_t);
95  template <typename T> uint32_t
96  find(const array_t<T>&, const array_t<uint32_t>&, const T&, uint32_t);
97 
99  template <typename T, class C>
100  struct heap {
102  std::vector<T*> data_;
104  const C comp_;
105 
108  heap<T, C>() : data_(), comp_() {}
109 
111  bool empty() const {return data_.empty();}
112 
114  size_t size() const {return data_.size();}
115 
117  void reserve(size_t n) {data_.reserve(n);}
118 
120  T* top() const {return data_[0];}
121 
123  void push(T* v) {
124  data_.push_back(v);
125  std::push_heap(data_.begin(), data_.end(), comp_);
126  }
127 
129  void pop() {
130  const size_t oldsize = data_.size();
131  std::pop_heap(data_.begin(), data_.end(), comp_);
132  data_.resize(oldsize-1);
133  }
134  }; // heap
135  } // namespace util
136 } // namespace ibis
137 #endif
138 
void sortAll(array_t< T1 > &arr1, array_t< T2 > &arr2)
Sort two arrays together.
Definition: utilidor.cpp:285
size_t size() const
The number of elements in the heap.
Definition: utilidor.h:114
void pop()
Remove the top element from the heap.
Definition: utilidor.h:129
std::vector< T * > data_
A vector to hold pointers to the underlying data.
Definition: utilidor.h:102
void sortRIDsq(ibis::RIDSet &, uint32_t, uint32_t)
Sort a portion of the RIDSet with quick sort.
Definition: utilidor.cpp:126
size_t find(const std::vector< T > &, const T &, size_t)
Find the first position where the value is no less than val.
Definition: utilidor.cpp:3795
The current implementation of FastBit is code named IBIS; most data structures and functions are in t...
Definition: bord.h:16
bool empty() const
Is the heap empty. Returns true if yes.
Definition: utilidor.h:111
void push(T *v)
Add a new element to the heap.
Definition: utilidor.h:123
void sortStrings(std::vector< std::string > &keys, array_t< uint32_t > &vals)
Sorting function with string as keys and uint32_t as payload.
Definition: utilidor.cpp:1244
void reserve(size_t n)
Reserve space.
Definition: utilidor.h:117
void sortKeys(array_t< T1 > &keys, array_t< T2 > &vals)
Sorting function with payload.
Definition: utilidor.cpp:564
void reorder(array_t< T > &arr, const array_t< uint32_t > &ind)
Reorder the array arr according to the indices given in ind.
Definition: utilidor.cpp:224
void sortRIDs(ibis::RIDSet &)
Sort RID lists.
Definition: utilidor.cpp:117
void sortRIDsi(ibis::RIDSet &, uint32_t, uint32_t)
Sort a portion of the RIDset with insertion sort.
Definition: utilidor.cpp:195
const C comp_
An object of the comparator type.
Definition: utilidor.h:104
A simple heap based on std::push_heap and std::pop_heap.
Definition: utilidor.h:100
T * top() const
The top element. No error checking!
Definition: utilidor.h:120
int64_t sortMerge(std::vector< std::string > &valR, array_t< uint32_t > &indR, std::vector< std::string > &valS, array_t< uint32_t > &indS)
An in-memory sort merge join function with string values.
Definition: utilidor.cpp:3346

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