/Users/deen/code/yugabyte-db/src/yb/common/key_encoder.cc
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include <functional> |
34 | | #include <string> |
35 | | #include <vector> |
36 | | |
37 | | |
38 | | #include "yb/common/common.pb.h" |
39 | | #include "yb/common/key_encoder.h" |
40 | | #include "yb/gutil/map-util.h" |
41 | | #include "yb/gutil/singleton.h" |
42 | | #include "yb/util/faststring.h" |
43 | | |
44 | | using std::shared_ptr; |
45 | | using std::unordered_map; |
46 | | |
47 | | namespace yb { |
48 | | |
49 | | |
50 | | // A resolver for Encoders |
51 | | template <typename Buffer> |
52 | | class EncoderResolver { |
53 | | public: |
54 | 5.92k | const KeyEncoder<Buffer>& GetKeyEncoder(DataType t) { |
55 | 5.92k | return *FindOrDie(encoders_, t); |
56 | 5.92k | } _ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE13GetKeyEncoderENS_8DataTypeE Line | Count | Source | 54 | 5.90k | const KeyEncoder<Buffer>& GetKeyEncoder(DataType t) { | 55 | 5.90k | return *FindOrDie(encoders_, t); | 56 | 5.90k | } |
_ZN2yb15EncoderResolverINS_10faststringEE13GetKeyEncoderENS_8DataTypeE Line | Count | Source | 54 | 11 | const KeyEncoder<Buffer>& GetKeyEncoder(DataType t) { | 55 | 11 | return *FindOrDie(encoders_, t); | 56 | 11 | } |
|
57 | | |
58 | 11.1k | const bool HasKeyEncoderForType(DataType t) { |
59 | 11.1k | return ContainsKey(encoders_, t); |
60 | 11.1k | } |
61 | | |
62 | | private: |
63 | 6.88k | EncoderResolver<Buffer>() { |
64 | 6.88k | AddMapping<BOOL>(); |
65 | 6.88k | AddMapping<UINT8>(); |
66 | 6.88k | AddMapping<INT8>(); |
67 | 6.88k | AddMapping<UINT16>(); |
68 | 6.88k | AddMapping<INT16>(); |
69 | 6.88k | AddMapping<UINT32>(); |
70 | 6.88k | AddMapping<INT32>(); |
71 | 6.88k | AddMapping<UINT64>(); |
72 | 6.88k | AddMapping<INT64>(); |
73 | 6.88k | AddMapping<BINARY>(); |
74 | 6.88k | AddMapping<FLOAT>(); |
75 | 6.88k | AddMapping<DOUBLE>(); |
76 | 6.88k | } _ZN2yb15EncoderResolverINS_10faststringEEC2Ev Line | Count | Source | 63 | 1.44k | EncoderResolver<Buffer>() { | 64 | 1.44k | AddMapping<BOOL>(); | 65 | 1.44k | AddMapping<UINT8>(); | 66 | 1.44k | AddMapping<INT8>(); | 67 | 1.44k | AddMapping<UINT16>(); | 68 | 1.44k | AddMapping<INT16>(); | 69 | 1.44k | AddMapping<UINT32>(); | 70 | 1.44k | AddMapping<INT32>(); | 71 | 1.44k | AddMapping<UINT64>(); | 72 | 1.44k | AddMapping<INT64>(); | 73 | 1.44k | AddMapping<BINARY>(); | 74 | 1.44k | AddMapping<FLOAT>(); | 75 | 1.44k | AddMapping<DOUBLE>(); | 76 | 1.44k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEC2Ev Line | Count | Source | 63 | 5.43k | EncoderResolver<Buffer>() { | 64 | 5.43k | AddMapping<BOOL>(); | 65 | 5.43k | AddMapping<UINT8>(); | 66 | 5.43k | AddMapping<INT8>(); | 67 | 5.43k | AddMapping<UINT16>(); | 68 | 5.43k | AddMapping<INT16>(); | 69 | 5.43k | AddMapping<UINT32>(); | 70 | 5.43k | AddMapping<INT32>(); | 71 | 5.43k | AddMapping<UINT64>(); | 72 | 5.43k | AddMapping<INT64>(); | 73 | 5.43k | AddMapping<BINARY>(); | 74 | 5.43k | AddMapping<FLOAT>(); | 75 | 5.43k | AddMapping<DOUBLE>(); | 76 | 5.43k | } |
|
77 | | |
78 | 82.5k | template<DataType Type> void AddMapping() { |
79 | 82.5k | KeyEncoderTraits<Type, Buffer> traits; |
80 | 82.5k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); |
81 | 82.5k | } _ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE6EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE100EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE1EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE101EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE2EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE102EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE3EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE103EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE4EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE9EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE7EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINS_10faststringEE10AddMappingILNS_8DataTypeE8EEEvv Line | Count | Source | 78 | 1.44k | template<DataType Type> void AddMapping() { | 79 | 1.44k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 1.44k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 1.44k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE6EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE100EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE1EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE101EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE2EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE102EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE3EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE103EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE4EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE9EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE7EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
_ZN2yb15EncoderResolverINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEE10AddMappingILNS_8DataTypeE8EEEvv Line | Count | Source | 78 | 5.43k | template<DataType Type> void AddMapping() { | 79 | 5.43k | KeyEncoderTraits<Type, Buffer> traits; | 80 | 5.43k | InsertOrDie(&encoders_, Type, shared_ptr<KeyEncoder<Buffer> >(new KeyEncoder<Buffer>(traits))); | 81 | 5.43k | } |
|
82 | | |
83 | | friend class Singleton<EncoderResolver<Buffer> >; |
84 | | unordered_map<DataType, shared_ptr<KeyEncoder<Buffer> >, std::hash<size_t> > encoders_; |
85 | | }; |
86 | | |
87 | | template <typename Buffer> |
88 | 5.92k | const KeyEncoder<Buffer>& GetKeyEncoder(const TypeInfo* typeinfo) { |
89 | 5.92k | return Singleton<EncoderResolver<Buffer> >::get()->GetKeyEncoder(typeinfo->physical_type()); |
90 | 5.92k | } _ZN2yb13GetKeyEncoderINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEERKNS_10KeyEncoderIT_EEPKNS_8TypeInfoE Line | Count | Source | 88 | 5.90k | const KeyEncoder<Buffer>& GetKeyEncoder(const TypeInfo* typeinfo) { | 89 | 5.90k | return Singleton<EncoderResolver<Buffer> >::get()->GetKeyEncoder(typeinfo->physical_type()); | 90 | 5.90k | } |
_ZN2yb13GetKeyEncoderINS_10faststringEEERKNS_10KeyEncoderIT_EEPKNS_8TypeInfoE Line | Count | Source | 88 | 11 | const KeyEncoder<Buffer>& GetKeyEncoder(const TypeInfo* typeinfo) { | 89 | 11 | return Singleton<EncoderResolver<Buffer> >::get()->GetKeyEncoder(typeinfo->physical_type()); | 90 | 11 | } |
|
91 | | |
92 | | // Returns true if the type is allowed in keys. |
93 | 11.1k | bool IsTypeAllowableInKey(const TypeInfo* typeinfo) { |
94 | 11.1k | return Singleton<EncoderResolver<faststring> >::get()->HasKeyEncoderForType( |
95 | 11.1k | typeinfo->physical_type()); |
96 | 11.1k | } |
97 | | |
98 | | //------------------------------------------------------------ |
99 | | //// Template instantiations: We instantiate all possible templates to avoid linker issues. |
100 | | //// see: https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl |
101 | | ////------------------------------------------------------------ |
102 | | |
103 | | template |
104 | | const KeyEncoder<string>& GetKeyEncoder(const TypeInfo* typeinfo); |
105 | | |
106 | | template |
107 | | const KeyEncoder<faststring>& GetKeyEncoder(const TypeInfo* typeinfo); |
108 | | |
109 | | } // namespace yb |