]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/btree_map.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / include / btree_map.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_INCLUDE_BTREE_MAP_H
5 #define CEPH_INCLUDE_BTREE_MAP_H
6
7 #include "include/cpp-btree/btree.h"
8 #include "include/cpp-btree/btree_map.h"
9 #include "include/ceph_assert.h" // cpp-btree uses system assert, blech
10 #include "include/encoding.h"
11
12 template<class T, class U>
13 inline void encode(const btree::btree_map<T,U>& m, ceph::buffer::list& bl)
14 {
15 using ceph::encode;
16 __u32 n = (__u32)(m.size());
17 encode(n, bl);
18 for (typename btree::btree_map<T,U>::const_iterator p = m.begin(); p != m.end(); ++p) {
19 encode(p->first, bl);
20 encode(p->second, bl);
21 }
22 }
23 template<class T, class U>
24 inline void encode(const btree::btree_map<T,U>& m, ceph::buffer::list& bl, uint64_t features)
25 {
26 using ceph::encode;
27 __u32 n = (__u32)(m.size());
28 encode(n, bl);
29 for (typename btree::btree_map<T,U>::const_iterator p = m.begin(); p != m.end(); ++p) {
30 encode(p->first, bl, features);
31 encode(p->second, bl, features);
32 }
33 }
34 template<class T, class U>
35 inline void decode(btree::btree_map<T,U>& m, ceph::buffer::list::const_iterator& p)
36 {
37 using ceph::decode;
38 __u32 n;
39 decode(n, p);
40 m.clear();
41 while (n--) {
42 T k;
43 decode(k, p);
44 decode(m[k], p);
45 }
46 }
47 template<class T, class U>
48 inline void encode_nohead(const btree::btree_map<T,U>& m, ceph::buffer::list& bl)
49 {
50 using ceph::encode;
51 for (typename btree::btree_map<T,U>::const_iterator p = m.begin(); p != m.end(); ++p) {
52 encode(p->first, bl);
53 encode(p->second, bl);
54 }
55 }
56 template<class T, class U>
57 inline void decode_nohead(int n, btree::btree_map<T,U>& m, ceph::buffer::list::const_iterator& p)
58 {
59 using ceph::decode;
60 m.clear();
61 while (n--) {
62 T k;
63 decode(k, p);
64 decode(m[k], p);
65 }
66 }
67
68 #endif