GRPC Core  9.0.0
map.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_GPRPP_MAP_H
20 #define GRPC_CORE_LIB_GPRPP_MAP_H
21 
23 
24 #include <string.h>
25 
26 #include <map>
27 
30 
31 namespace grpc_core {
32 
33 struct StringLess {
34  bool operator()(const char* a, const char* b) const {
35  return strcmp(a, b) < 0;
36  }
38  const grpc_core::UniquePtr<char>& b) const {
39  return strcmp(a.get(), b.get()) < 0;
40  }
41  bool operator()(const StringView& a, const StringView& b) const {
42  const size_t min_size = std::min(a.size(), b.size());
43  int c = strncmp(a.data(), b.data(), min_size);
44  if (c != 0) return c < 0;
45  return a.size() < b.size();
46  }
47 };
48 
49 template <typename T>
51  bool operator()(const RefCountedPtr<T>& p1,
52  const RefCountedPtr<T>& p2) const {
53  return p1.get() < p2.get();
54  }
55 };
56 
57 } // namespace grpc_core
58 
59 #endif /* GRPC_CORE_LIB_GPRPP_MAP_H */
Definition: ref_counted_ptr.h:35
T * get() const
Definition: ref_counted_ptr.h:144
Definition: string_view.h:69
constexpr size_t size() const
Definition: string_view.h:79
constexpr const char * data() const
Definition: string_view.h:78
Round Robin Policy.
Definition: backend_metric.cc:24
std::unique_ptr< T, DefaultDeleteChar > UniquePtr
Definition: memory.h:45
Definition: map.h:50
bool operator()(const RefCountedPtr< T > &p1, const RefCountedPtr< T > &p2) const
Definition: map.h:51
Definition: map.h:33
bool operator()(const grpc_core::UniquePtr< char > &a, const grpc_core::UniquePtr< char > &b) const
Definition: map.h:37
bool operator()(const char *a, const char *b) const
Definition: map.h:34
bool operator()(const StringView &a, const StringView &b) const
Definition: map.h:41