#define CEPH_FRAG_H
#include <stdint.h>
-#include <map>
#include <list>
#include <iostream>
#include <stdio.h>
#include "buffer.h"
+#include "compact_map.h"
#include "ceph_frag.h"
#include "include/assert.h"
// frag_t f is split by b bits.
// if child frag_t does not appear, it is not split.
public:
- std::map<frag_t,int32_t> _splits;
+ compact_map<frag_t,int32_t> _splits;
public:
// -------------
return _splits.empty();
}
int get_split(const frag_t hb) const {
- std::map<frag_t,int32_t>::const_iterator p = _splits.find(hb);
+ compact_map<frag_t,int32_t>::const_iterator p = _splits.find(hb);
if (p == _splits.end())
return 0;
else
void decode(bufferlist::iterator& p) {
::decode(_splits, p);
}
+ void encode_nohead(bufferlist& bl) const {
+ for (compact_map<frag_t,int32_t>::const_iterator p = _splits.begin();
+ p != _splits.end();
+ ++p) {
+ ::encode(p->first, bl);
+ ::encode(p->second, bl);
+ }
+ }
+ void decode_nohead(int n, bufferlist::iterator& p) {
+ _splits.clear();
+ while (n-- > 0) {
+ frag_t f;
+ ::decode(f, p);
+ ::decode(_splits[f], p);
+ }
+ }
void print(std::ostream& out) {
out << "fragtree_t(";
{
out << "fragtree_t(";
- for (std::map<frag_t,int32_t>::const_iterator p = ft._splits.begin();
+ for (compact_map<frag_t,int32_t>::const_iterator p = ft._splits.begin();
p != ft._splits.end();
- p++) {
+ ++p) {
if (p != ft._splits.begin())
out << " ";
out << p->first << "^" << p->second;
// encode
e.fragtree.nsplits = dirfragtree._splits.size();
::encode(e, bl);
- for (map<frag_t,int32_t>::iterator p = dirfragtree._splits.begin();
- p != dirfragtree._splits.end();
- ++p) {
- ::encode(p->first, bl);
- ::encode(p->second, bl);
- }
+
+ dirfragtree.encode_nohead(bl);
+
::encode(symlink, bl);
if (session->connection->has_feature(CEPH_FEATURE_DIRLAYOUTHASH)) {
i = pfile ? pi : oi;
rstat.rfiles = e.rfiles;
rstat.rsubdirs = e.rsubdirs;
- int n = e.fragtree.nsplits;
- while (n) {
- ceph_frag_tree_split s;
- ::decode(s, p);
- dirfragtree._splits[(__u32)s.frag] = s.by;
- n--;
- }
+ dirfragtree.decode_nohead(e.fragtree.nsplits, p);
+
::decode(symlink, p);
if (features & CEPH_FEATURE_DIRLAYOUTHASH)