From 5e8a9e02a65c9cdaaf03ffa9adf6d66c706ea7f2 Mon Sep 17 00:00:00 2001 From: sageweil Date: Mon, 27 Aug 2007 15:00:21 +0000 Subject: [PATCH] bitmapper, etc. git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1704 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/include/bitmapper.h | 39 +++++++++++++++++++++++++++++++ trunk/ceph/include/interval_set.h | 9 +++++++ trunk/ceph/include/xlist.h | 4 ++++ 3 files changed, 52 insertions(+) create mode 100644 trunk/ceph/include/bitmapper.h diff --git a/trunk/ceph/include/bitmapper.h b/trunk/ceph/include/bitmapper.h new file mode 100644 index 0000000000000..49ba6457bbabd --- /dev/null +++ b/trunk/ceph/include/bitmapper.h @@ -0,0 +1,39 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + + +#ifndef __BITMAPPER_H +#define __BITMAPPER_H + +class bitmapper { + char *_data; + + public: + bitmapper(char *data) : _data(data) { } + + bool operator[](int b) { + return _data[b >> 3] & (1 << (b&7)); + } + void set(int b) { + _data[b >> 3] |= 1 << (b&7); + } + void clear(int b) { + _data[b >> 3] &= ~(1 << (b&7)); + } + void toggle(int b) { + _data[b >> 3] ^= 1 << (b&7); + } +}; + +#endif diff --git a/trunk/ceph/include/interval_set.h b/trunk/ceph/include/interval_set.h index 632fd6498c910..bc5edbc29441d 100644 --- a/trunk/ceph/include/interval_set.h +++ b/trunk/ceph/include/interval_set.h @@ -33,6 +33,7 @@ template class interval_set { public: map m; // map start -> len + int _size; // helpers private: @@ -85,8 +86,13 @@ class interval_set { return m == other.m; } + int size() { + return _size; + } + void clear() { m.clear(); + _size = 0; } bool contains(T i) const { @@ -158,6 +164,7 @@ class interval_set { void insert(T start, T len) { //cout << "insert " << start << "~" << len << endl; assert(len > 0); + _size += len; typename map::iterator p = find_adj_m(start); if (p == m.end()) { m[start] = len; // new interval @@ -198,6 +205,8 @@ class interval_set { void erase(T start, T len) { typename map::iterator p = find_inc_m(start); + _size -= len; + assert(p != m.end()); assert(p->first <= start); diff --git a/trunk/ceph/include/xlist.h b/trunk/ceph/include/xlist.h index 901e62bf10a40..91e5ebbdd68ef 100644 --- a/trunk/ceph/include/xlist.h +++ b/trunk/ceph/include/xlist.h @@ -98,6 +98,10 @@ public: int size() { return _size; } bool empty() { return _front == 0; } + void clear() { + while (_front) remove(_front); + } + void push_back(item *item) { if (item->_head) item->_head->remove(item); -- 2.39.5