xmap.h
// xmap.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2008
@import "SelectBPlusTree.h"
namespace ceda
{
///////////////////////////////////////////////////////////////////////////////////////////////////
// xmap
/*
xmap<K,V> is basically an alias for cref< BTree<K,V> > with the following additional
changes
* ==, !=, < modified to work on the B+Tree rather than the cref
* copy ctor, assignment ???
Note that serialisation of the model attribute serialises the cref as we require.
*/
/*
During read access to a B+Tree we are careful to avoid insertion of (key,payload) entries
with a default constructed payload. Note that any insertions into a B+Tree can cause
complex changes (e.g. as nodes overflow and split), and this would cause problems with
concurrent read only access to the B+Tree.
*/
template <typename K, typename V>
class xmap : public bplustreemap<K,V>
{
public:
using typename bplustreemap<K,V>::key_type;
using typename bplustreemap<K,V>::const_iterator;
///////////////////////////////////////////////////////////////////////////
// Implementation of IXMap
void Construct()
{
new(this) xmap();
}
void CopyConstruct(const void* rhs)
{
new(this) xmap( *reinterpret_cast<const xmap*>(rhs) );
}
void CopyAssign(const void* rhs)
{
*this = *reinterpret_cast<const xmap*>(rhs);
}
ssize_t GetKeySize() const
{
return sizeof(key_type);
}
const void* Get(const void* key) const
{
return this->find_2(*(key_type*)key);
}
void Search(InputArchive& ar, const void*& payload) const
{
key_type key;
ar >> key;
payload = this->find_2(key);
}
void DeserialiseAndInsert(InputArchive& ar, void*& payload)
{
key_type key;
ar >> key;
payload = &(*this)[key];
}
void* Insert(const void* key)
{
return &(*this)[* (const key_type*) key];
}
ptr<IBiDirIterator> GetIterator() const
{
return new BTreeIterator<const_iterator>(this->begin());
}
ptr<IKeyType> GetKeyType() const
{
static KeyType<key_type> s;
return &s;
}
};
} // namespace ceda