全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 ページ
groupComp.h
1 #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_GROUPCOMP_H
2 #define BZS_DB_PROTOCOL_TDAP_CLIENT_GROUPCOMP_H
3 /*=================================================================
4  Copyright (C) 2014-2016 BizStation Corp All rights reserved.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (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, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20 =================================================================*/
21 
22 namespace bzs
23 {
24 namespace db
25 {
26 namespace protocol
27 {
28 namespace tdap
29 {
30 namespace client
31 {
32 
33 /** @cond INTERNAL */
34 
35 template <class Container, class FUNC>
36 int binary_search(int key, const Container& a, int left, int right, FUNC func,
37  bool& find)
38 {
39  find = false;
40  if (right == 0)
41  return 0; // no size
42 
43  int mid, tmp, end = right;
44  while (left <= right)
45  {
46  mid = (left + right) / 2;
47  if (mid >= end)
48  return end;
49  if ((tmp = func(a[mid], key)) == 0)
50  {
51  find = true;
52  return mid;
53  }
54  else if (tmp < 0)
55  left = mid + 1; // keyValue is more large
56  else
57  right = mid - 1; // keyValue is more small
58  }
59  return left;
60 }
61 
62 inline int compByKey(const fieldsBase& l, const fieldsBase& r, const int& s)
63 {
64  assert((s < (int)l.size()) && (s < (int)r.size()));
65  return l.getFieldNoCheck(s).comp(r.getFieldNoCheck(s), CMPLOGICAL_VAR_COMP_ALL);
66 }
67 
68 template <class Container> class grouping_comp
69 {
70  typedef std::vector<typename Container::key_type> key_vec;
71  const key_vec& m_keys;
72  Container& m_mdls;
73 
74 public:
75  grouping_comp(Container& mdls,
76  const std::vector<typename Container::key_type>& keys)
77  : m_keys(keys), m_mdls(mdls)
78  {
79  }
80 
81  int operator()(int lv, int rv) const
82  {
83  const typename Container::row_pure_type& lm = m_mdls[lv];
84  const typename Container::row_pure_type& rm = m_mdls[rv];
85  for (int i = 0; i < (int)m_keys.size(); ++i)
86  {
87  typename Container::key_type s = m_keys[i];
88  int ret = (s == -1) ? 0 : compByKey(lm, rm, s);
89  if (ret)
90  return ret;
91  }
92  return 0;
93  }
94 
95  bool isEqual(const typename Container::row_type& lm,
96  const typename Container::row_type& rm)
97  {
98  for (int i = 0; i < m_keys.size(); ++i)
99  {
100  typename Container::key_type s = m_keys[i];
101  int ret = (s == -1) ? 0 : compByKey(*lm, *rm, s);
102  if (ret)
103  return false;
104  }
105  return true;
106  }
107 };
108 
109 /** @endcond */
110 
111 } // namespace client
112 } // namespace tdap
113 } // namespace protocol
114 } // namespace db
115 } // namespace bzs
116 
117 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_GROUPCOMP_H
findIterator find(table_ptr tb, const char_td keynum, const Q &q, const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4, const T5 kv5, const T6 kv6, const T7 kv7)
Definition: trdboostapi.h:589

Transactd SDK 2018年07月31日(火) 19時40分21秒 doxygen