Removed the AVLTree implementation and used the kernel utils version

instead. Quite a few changes to account for the different interfaces.
The add-on size dropped from 438 to 302 KB, which is still quite heavy.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21893 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-08-11 15:02:22 +00:00
parent 2529455101
commit 6ad9efd671
11 changed files with 316 additions and 1229 deletions
File diff suppressed because it is too large Load Diff
@@ -142,12 +142,8 @@ public:
AttributeTree(uint32 type) AttributeTree(uint32 type)
: TwoKeyAVLTree<Attribute*, PrimaryKey, PrimaryKeyCompare, : TwoKeyAVLTree<Attribute*, PrimaryKey, PrimaryKeyCompare,
GetPrimaryKey>(PrimaryKeyCompare(type), GetPrimaryKey>(PrimaryKeyCompare(type),
GetPrimaryKey(), AVLTreeStandardCompare<Attribute*>(), GetPrimaryKey(), TwoKeyAVLTreeStandardCompare<Attribute*>(),
AVLTreeStandardGetKey<Attribute*, Attribute*>(), TwoKeyAVLTreeStandardGetKey<Attribute*, Attribute*>())
AVLTreeStandardNodeAllocator<Attribute*,
AVLTreeStandardNode<Attribute*> >(),
AVLTreeStandardGetValue<Attribute*,
AVLTreeStandardNode<Attribute*> >())
{ {
} }
}; };
@@ -254,7 +250,7 @@ AttributeIndexImpl::Changed(Attribute *attribute, const uint8 *oldKey,
iterator->NodeRemoved(node); iterator->NodeRemoved(node);
} }
// remove and re-insert the attribute // remove and re-insert the attribute
fAttributes->Remove(it); it.Remove();
} }
} }
// re-insert the attribute // re-insert the attribute
@@ -4,6 +4,8 @@ local userlandFSTop = [ FDirName $(HAIKU_TOP) src add-ons kernel
file_systems userlandfs ] ; file_systems userlandfs ] ;
local userlandFSIncludes = [ PrivateHeaders userlandfs ] ; local userlandFSIncludes = [ PrivateHeaders userlandfs ] ;
UsePrivateHeaders kernel ; # for <util/*>
SubDirHdrs [ FDirName $(userlandFSIncludes) shared ] ; SubDirHdrs [ FDirName $(userlandFSIncludes) shared ] ;
SEARCH_SOURCE += [ FDirName $(userlandFSTop) shared ] ; SEARCH_SOURCE += [ FDirName $(userlandFSTop) shared ] ;
@@ -158,7 +158,7 @@ LastModifiedIndex::Changed(Node *node, time_t oldModified)
iterator->NodeRemoved(node); iterator->NodeRemoved(node);
} }
// remove and re-insert the node // remove and re-insert the node
fNodes->Remove(it); it.Remove();
error = fNodes->Insert(node); error = fNodes->Insert(node);
// udpate live queries // udpate live queries
@@ -137,7 +137,7 @@ NameIndex::Changed(Entry *entry, const char *oldName)
Entry **foundEntry Entry **foundEntry
= fEntries->Find(NameIndexPrimaryKey(entry, oldName), entry, &it); = fEntries->Find(NameIndexPrimaryKey(entry, oldName), entry, &it);
if (foundEntry && *foundEntry == entry) { if (foundEntry && *foundEntry == entry) {
fEntries->Remove(it); it.Remove();
error = fEntries->Insert(entry); error = fEntries->Insert(entry);
// udpate live queries // udpate live queries
@@ -105,6 +105,19 @@ IndexIterator::Find(const uint8 *const key, size_t keyLength)
return error; return error;
} }
// Rewind
status_t
IndexIterator::Rewind()
{
status_t error = B_ENTRY_NOT_FOUND;
if (fIndexWrapper && fIndexWrapper->fIndex) {
fInitialized = fIndexWrapper->fIndex->GetIterator(&fIterator);
if (fInitialized)
error = B_OK;
}
return error;
}
// GetNextEntry // GetNextEntry
status_t status_t
IndexIterator::GetNextEntry(uint8 *buffer, uint16 *_keyLength, IndexIterator::GetNextEntry(uint8 *buffer, uint16 *_keyLength,
@@ -1119,8 +1132,10 @@ Equation::PrepareQuery(Volume */*volume*/, IndexWrapper &index, IndexIterator **
if (fOp == OP_EQUAL && !fIsPattern) if (fOp == OP_EQUAL && !fIsPattern)
return status; return status;
else if (status == B_ENTRY_NOT_FOUND else if (status == B_ENTRY_NOT_FOUND
&& (fIsPattern || fOp == OP_GREATER_THAN || fOp == OP_GREATER_THAN_OR_EQUAL)) && (fIsPattern || fOp == OP_GREATER_THAN
return B_OK; || fOp == OP_GREATER_THAN_OR_EQUAL)) {
return (*iterator)->Rewind();
}
RETURN_ERROR(status); RETURN_ERROR(status);
} }
@@ -57,6 +57,7 @@ public:
IndexIterator(IndexWrapper *indexWrapper); IndexIterator(IndexWrapper *indexWrapper);
status_t Find(const uint8 *const key, size_t keyLength); status_t Find(const uint8 *const key, size_t keyLength);
status_t Rewind();
status_t GetNextEntry(uint8 *buffer, uint16 *keyLength, size_t bufferSize, status_t GetNextEntry(uint8 *buffer, uint16 *keyLength, size_t bufferSize,
Entry **entry); Entry **entry);
@@ -157,7 +157,7 @@ SizeIndex::Changed(Node *node, off_t oldSize)
} }
// remove and re-insert the node // remove and re-insert the node
fNodes->Remove(it); it.Remove();
error = fNodes->Insert(node); error = fNodes->Insert(node);
// udpate live queries // udpate live queries
@@ -1,34 +1,12 @@
// TwoKeyAVLTree.h /*
// * Copyright 2003-2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
// Copyright (c) 2003, Ingo Weinhold ([email protected]) * Distributed under the terms of the MIT License.
// */
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of a copyright holder shall
// not be used in advertising or otherwise to promote the sale, use or other
// dealings in this Software without prior written authorization of the
// copyright holder.
#ifndef TWO_KEY_AVL_TREE_H #ifndef TWO_KEY_AVL_TREE_H
#define TWO_KEY_AVL_TREE_H #define TWO_KEY_AVL_TREE_H
#include "AVLTree.h" #include <util/AVLTreeMap.h>
// TwoKeyAVLTreeKey // TwoKeyAVLTreeKey
template<typename PrimaryKey, typename SecondaryKey> template<typename PrimaryKey, typename SecondaryKey>
@@ -105,56 +83,172 @@ private:
GetSecondaryKey fGetSecondaryKey; GetSecondaryKey fGetSecondaryKey;
}; };
// TwoKeyAVLTreeStandardCompare
template<typename Value>
class TwoKeyAVLTreeStandardCompare
{
public:
inline int operator()(const Value &a, const Value &b) const
{
if (a < b)
return -1;
else if (a > b)
return 1;
return 0;
}
};
// TwoKeyAVLTreeStandardGetKey
template<typename Value, typename Key>
class TwoKeyAVLTreeStandardGetKey
{
public:
inline const Key &operator()(const Value &a) const
{
return a;
}
inline Key &operator()(Value &a) const
{
return a;
}
};
// TwoKeyAVLTreeNodeStrategy
template <typename PrimaryKey, typename SecondaryKey, typename Value,
typename PrimaryKeyCompare, typename SecondaryKeyCompare,
typename GetPrimaryKey, typename GetSecondaryKey>
class TwoKeyAVLTreeNodeStrategy {
public:
typedef TwoKeyAVLTreeKey<PrimaryKey, SecondaryKey> Key;
TwoKeyAVLTreeNodeStrategy(
const PrimaryKeyCompare& primaryKeyCompare = PrimaryKeyCompare(),
const SecondaryKeyCompare& secondaryKeyCompare = SecondaryKeyCompare(),
const GetPrimaryKey& getPrimaryKey = GetPrimaryKey(),
const GetSecondaryKey& getSecondaryKey = GetSecondaryKey())
: fPrimaryKeyCompare(primaryKeyCompare),
fSecondaryKeyCompare(secondaryKeyCompare),
fGetPrimaryKey(getPrimaryKey),
fGetSecondaryKey(getSecondaryKey)
{
}
struct Node : AVLTreeNode {
Node(const Value &value)
: AVLTreeNode(),
value(value)
{
}
Value value;
};
inline Node* Allocate(const Key& key, const Value& value) const
{
return new(nothrow) Node(value);
}
inline void Free(Node* node) const
{
delete node;
}
// internal use (not part of the strategy)
inline Key GetValueKey(const Value& value) const
{
return Key(fGetPrimaryKey(value), fGetSecondaryKey(value));
}
inline Key GetKey(Node* node) const
{
return GetValueKey(node->value);
}
inline Value& GetValue(Node* node) const
{
return node->value;
}
inline AVLTreeNode* GetAVLTreeNode(Node* node) const
{
return node;
}
inline Node* GetNode(AVLTreeNode* node) const
{
return static_cast<Node*>(node);
}
inline int CompareKeyNode(const Key& a, const Node* b) const
{
return _CompareKeys(a, GetKey(const_cast<Node*>(b)));
}
inline int CompareNodes(const Node* a, const Node* b) const
{
return _CompareKeys(GetKey(const_cast<Node*>(a)),
GetKey(const_cast<Node*>(b)));
}
private:
inline int _CompareKeys(const Key& a, const Key& b) const
{
int result = fPrimaryKeyCompare(a.primary, b.primary);
if (result == 0 && a.use_secondary && b.use_secondary)
result = fSecondaryKeyCompare(a.secondary, b.secondary);
return result;
}
PrimaryKeyCompare fPrimaryKeyCompare;
SecondaryKeyCompare fSecondaryKeyCompare;
GetPrimaryKey fGetPrimaryKey;
GetSecondaryKey fGetSecondaryKey;
};
// for convenience // for convenience
#define TWO_KEY_AVL_TREE_TEMPLATE_LIST template<typename Value, \ #define TWO_KEY_AVL_TREE_TEMPLATE_LIST template<typename Value, \
typename PrimaryKey, typename PrimaryKeyCompare, \ typename PrimaryKey, typename PrimaryKeyCompare, \
typename GetPrimaryKey, typename SecondaryKey, typename Node, \ typename GetPrimaryKey, typename SecondaryKey, \
typename SecondaryKeyCompare, typename GetSecondaryKey, \ typename SecondaryKeyCompare, typename GetSecondaryKey>
typename NodeAllocator, typename GetValue>
#define TWO_KEY_AVL_TREE_CLASS_NAME TwoKeyAVLTree<Value, PrimaryKey, \ #define TWO_KEY_AVL_TREE_CLASS_NAME TwoKeyAVLTree<Value, PrimaryKey, \
PrimaryKeyCompare, GetPrimaryKey, SecondaryKey, Node, \ PrimaryKeyCompare, GetPrimaryKey, SecondaryKey, \
SecondaryKeyCompare, GetSecondaryKey, NodeAllocator, GetValue> SecondaryKeyCompare, GetSecondaryKey>
// TwoKeyAVLTree // TwoKeyAVLTree
template<typename Value, typename PrimaryKey, template<typename Value, typename PrimaryKey,
typename PrimaryKeyCompare, typename GetPrimaryKey, typename PrimaryKeyCompare, typename GetPrimaryKey,
typename SecondaryKey = Value, typename SecondaryKey = Value,
typename Node = AVLTreeStandardNode<Value>, typename SecondaryKeyCompare
typename SecondaryKeyCompare = AVLTreeStandardCompare<SecondaryKey>, = TwoKeyAVLTreeStandardCompare<SecondaryKey>,
typename GetSecondaryKey = AVLTreeStandardGetKey<Value, SecondaryKey>, typename GetSecondaryKey
typename NodeAllocator = AVLTreeStandardNodeAllocator<Value, Node>, = TwoKeyAVLTreeStandardGetKey<Value, SecondaryKey> >
typename GetValue = AVLTreeStandardGetValue<Value, Node> > class TwoKeyAVLTree {
class TwoKeyAVLTree : private AVLTree<Value, public:
TwoKeyAVLTreeKey<PrimaryKey, SecondaryKey>, Node,
TwoKeyAVLTreeKeyCompare<PrimaryKey, SecondaryKey, PrimaryKeyCompare,
SecondaryKeyCompare>,
TwoKeyAVLTreeGetKey<Value, PrimaryKey, SecondaryKey, GetPrimaryKey,
GetSecondaryKey>,
NodeAllocator, GetValue> {
private:
typedef TwoKeyAVLTreeKey<PrimaryKey, SecondaryKey> Key; typedef TwoKeyAVLTreeKey<PrimaryKey, SecondaryKey> Key;
typedef TwoKeyAVLTreeKeyCompare<PrimaryKey, SecondaryKey, typedef TwoKeyAVLTreeNodeStrategy<PrimaryKey, SecondaryKey, Value,
PrimaryKeyCompare, SecondaryKeyCompare> PrimaryKeyCompare, SecondaryKeyCompare, GetPrimaryKey,
KeyCompare; GetSecondaryKey> NodeStrategy;
typedef TwoKeyAVLTreeGetKey<Value, PrimaryKey, SecondaryKey, GetPrimaryKey, typedef AVLTreeMap<Key, Value, NodeStrategy> TreeMap;
GetSecondaryKey>
GetKey; typedef typename TreeMap::Iterator TreeMapIterator;
typedef AVLTree<Value, Key, Node, KeyCompare, GetKey, NodeAllocator, typedef typename NodeStrategy::Node Node;
GetValue> BaseClass;
public: class Iterator;
typedef typename BaseClass::Iterator Iterator;
public:
TwoKeyAVLTree(); TwoKeyAVLTree();
TwoKeyAVLTree(const PrimaryKeyCompare &primaryCompare, TwoKeyAVLTree(const PrimaryKeyCompare &primaryCompare,
const GetPrimaryKey &getPrimary, const GetPrimaryKey &getPrimary,
const SecondaryKeyCompare &secondaryCompare, const SecondaryKeyCompare &secondaryCompare,
const GetSecondaryKey &getSecondary, const GetSecondaryKey &getSecondary);
const NodeAllocator &allocator,
const GetValue &getValue);
~TwoKeyAVLTree(); ~TwoKeyAVLTree();
inline int CountItems() const { return BaseClass::CountItems(); } inline int CountItems() const { return fTreeMap.Count(); }
Value *FindFirst(const PrimaryKey &key, Iterator *iterator = NULL); Value *FindFirst(const PrimaryKey &key, Iterator *iterator = NULL);
Value *FindLast(const PrimaryKey &key, Iterator *iterator = NULL); Value *FindLast(const PrimaryKey &key, Iterator *iterator = NULL);
@@ -162,73 +256,145 @@ public:
const SecondaryKey &secondaryKey, const SecondaryKey &secondaryKey,
Iterator *iterator = NULL); Iterator *iterator = NULL);
inline void GetIterator(Iterator *iterator, bool reverse = false); inline void GetIterator(Iterator *iterator);
inline status_t Insert(const Value &value, Iterator *iterator = NULL); inline status_t Insert(const Value &value, Iterator *iterator = NULL);
inline status_t Remove(const PrimaryKey &primaryKey, inline status_t Remove(const PrimaryKey &primaryKey,
const SecondaryKey &secondaryKey); const SecondaryKey &secondaryKey);
inline void Remove(Iterator &iterator);
private: private:
TreeMap fTreeMap;
PrimaryKeyCompare fPrimaryKeyCompare; PrimaryKeyCompare fPrimaryKeyCompare;
GetPrimaryKey fGetPrimaryKey; GetPrimaryKey fGetPrimaryKey;
}; };
// Iterator
TWO_KEY_AVL_TREE_TEMPLATE_LIST
class TWO_KEY_AVL_TREE_CLASS_NAME::Iterator {
public:
typedef typename TWO_KEY_AVL_TREE_CLASS_NAME::TreeMapIterator
TreeMapIterator;
inline Iterator()
: fIterator()
{
}
inline ~Iterator()
{
}
inline Value *GetCurrent()
{
return fIterator.CurrentValuePointer();
}
inline Value *GetNext()
{
fIterator.Next();
return GetCurrent();
}
inline Value *GetPrevious()
{
fIterator.Previous();
return GetCurrent();
}
inline void Remove()
{
fIterator.Remove();
}
private:
friend class TWO_KEY_AVL_TREE_CLASS_NAME;
Iterator(const Iterator& other)
: fIterator(other.fIterator)
{
}
Iterator &operator=(const Iterator& other)
{
fIterator = other.fIterator;
}
Iterator(const TreeMapIterator &iterator)
: fIterator()
{
}
inline void _SetTo(const TreeMapIterator &iterator)
{
fIterator = iterator;
}
private:
TWO_KEY_AVL_TREE_CLASS_NAME::TreeMapIterator fIterator;
};
// constructor // constructor
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
TWO_KEY_AVL_TREE_CLASS_NAME::TwoKeyAVLTree() TWO_KEY_AVL_TREE_CLASS_NAME::TwoKeyAVLTree()
: BaseClass(KeyCompare(PrimaryKeyCompare(), SecondaryKeyCompare()), : fTreeMap(NodeStrategy(PrimaryKeyCompare(), SecondaryKeyCompare(),
GetKey(GetPrimaryKey(), GetSecondaryKey()), GetPrimaryKey(), GetSecondaryKey())),
NodeAllocator(), GetValue()) fPrimaryKeyCompare(PrimaryKeyCompare()),
fGetPrimaryKey(GetPrimaryKey())
{ {
} }
// constructor // constructor
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
TWO_KEY_AVL_TREE_CLASS_NAME::TwoKeyAVLTree( TWO_KEY_AVL_TREE_CLASS_NAME::TwoKeyAVLTree(
const PrimaryKeyCompare &primaryCompare, const GetPrimaryKey &getPrimary, const PrimaryKeyCompare &primaryCompare, const GetPrimaryKey &getPrimary,
const SecondaryKeyCompare &secondaryCompare, const SecondaryKeyCompare &secondaryCompare,
const GetSecondaryKey &getSecondary, const NodeAllocator &allocator, const GetSecondaryKey &getSecondary)
const GetValue &getValue) : fTreeMap(NodeStrategy(primaryCompare, secondaryCompare, getPrimary,
: BaseClass(KeyCompare(primaryCompare, secondaryCompare), getSecondary)),
GetKey(getPrimary, getSecondary),
allocator, getValue),
fPrimaryKeyCompare(primaryCompare), fPrimaryKeyCompare(primaryCompare),
fGetPrimaryKey(getPrimary) fGetPrimaryKey(getPrimary)
{ {
} }
// destructor // destructor
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
TWO_KEY_AVL_TREE_CLASS_NAME::~TwoKeyAVLTree() TWO_KEY_AVL_TREE_CLASS_NAME::~TwoKeyAVLTree()
{ {
} }
// FindFirst // FindFirst
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
Value * Value *
TWO_KEY_AVL_TREE_CLASS_NAME::FindFirst(const PrimaryKey &key, TWO_KEY_AVL_TREE_CLASS_NAME::FindFirst(const PrimaryKey &key,
Iterator *iterator) Iterator *iterator)
{ {
Node *node = BaseClass::fRoot; const NodeStrategy& strategy = fTreeMap.GetNodeStrategy();
Node *node = fTreeMap.RootNode();
while (node) { while (node) {
int cmp = fPrimaryKeyCompare(key, fGetPrimaryKey(fGetValue(node))); int cmp = fPrimaryKeyCompare(key, fGetPrimaryKey(
strategy.GetValue(node)));
if (cmp == 0) { if (cmp == 0) {
// found a matching node, now get the left-most node with that key // found a matching node, now get the left-most node with that key
while (node->left && fPrimaryKeyCompare(key, while (node->left && fPrimaryKeyCompare(key,
fGetPrimaryKey(fGetValue(node->left))) == 0) { fGetPrimaryKey(strategy.GetValue(
node = node->left; strategy.GetNode(node->left)))) == 0) {
node = strategy.GetNode(node->left);
} }
if (iterator) if (iterator)
_InitIterator(iterator, node); iterator->_SetTo(fTreeMap.GetIterator(node));
return &fGetValue(node); return &strategy.GetValue(node);
} }
if (cmp < 0) if (cmp < 0)
node = node->left; node = strategy.GetNode(node->left);
else else
node = node->right; node = strategy.GetNode(node->right);
} }
return NULL; return NULL;
} }
@@ -237,25 +403,30 @@ TWO_KEY_AVL_TREE_CLASS_NAME::FindFirst(const PrimaryKey &key,
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
Value * Value *
TWO_KEY_AVL_TREE_CLASS_NAME::FindLast(const PrimaryKey &key, TWO_KEY_AVL_TREE_CLASS_NAME::FindLast(const PrimaryKey &key,
Iterator *iterator) Iterator *iterator)
{ {
Node *node = BaseClass::fRoot; const NodeStrategy& strategy = fTreeMap.GetNodeStrategy();
Node *node = fTreeMap.RootNode();
while (node) { while (node) {
int cmp = fPrimaryKeyCompare(key, fGetPrimaryKey(fGetValue(node))); int cmp = fPrimaryKeyCompare(key, fGetPrimaryKey(
strategy.GetValue(node)));
if (cmp == 0) { if (cmp == 0) {
// found a matching node, now get the right-most node with that key // found a matching node, now get the right-most node with that key
while (node->right && fPrimaryKeyCompare(key, while (node->right && fPrimaryKeyCompare(key,
fGetPrimaryKey(fGetValue(node->right))) == 0) { fGetPrimaryKey(strategy.GetValue(
node = node->right; strategy.GetNode(node->right)))) == 0) {
node = strategy.GetNode(node->right);
} }
if (iterator) if (iterator)
_InitIterator(iterator, node); iterator->_SetTo(fTreeMap.GetIterator(node));
return &fGetValue(node); return &strategy.GetValue(node);
} }
if (cmp < 0) if (cmp < 0)
node = node->left; node = strategy.GetNode(node->left);
else else
node = node->right; node = strategy.GetNode(node->right);
} }
return NULL; return NULL;
} }
@@ -264,18 +435,24 @@ TWO_KEY_AVL_TREE_CLASS_NAME::FindLast(const PrimaryKey &key,
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
Value * Value *
TWO_KEY_AVL_TREE_CLASS_NAME::Find(const PrimaryKey &primaryKey, TWO_KEY_AVL_TREE_CLASS_NAME::Find(const PrimaryKey &primaryKey,
const SecondaryKey &secondaryKey, const SecondaryKey &secondaryKey, Iterator *iterator)
Iterator *iterator)
{ {
return BaseClass::Find(Key(primaryKey, secondaryKey), iterator);
TreeMapIterator it = fTreeMap.Find(Key(primaryKey, secondaryKey));
if (iterator)
iterator->_SetTo(it);
return it.CurrentValuePointer();
} }
// GetIterator // GetIterator
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
void void
TWO_KEY_AVL_TREE_CLASS_NAME::GetIterator(Iterator *iterator, bool reverse) TWO_KEY_AVL_TREE_CLASS_NAME::GetIterator(Iterator *iterator)
{ {
BaseClass::GetIterator(iterator, reverse); TreeMapIterator it = fTreeMap.GetIterator();
it.Next();
// Our iterator needs to point to the first entry already.
iterator->_SetTo(it);
} }
// Insert // Insert
@@ -283,24 +460,25 @@ TWO_KEY_AVL_TREE_TEMPLATE_LIST
status_t status_t
TWO_KEY_AVL_TREE_CLASS_NAME::Insert(const Value &value, Iterator *iterator) TWO_KEY_AVL_TREE_CLASS_NAME::Insert(const Value &value, Iterator *iterator)
{ {
return BaseClass::Insert(value, iterator); NodeStrategy& strategy
= const_cast<NodeStrategy&>(fTreeMap.GetNodeStrategy());
TreeMapIterator it;
status_t status = fTreeMap.Insert(strategy.GetValueKey(value), value, &it);
if (status != B_OK || !iterator)
return status;
iterator->_SetTo(it);
return B_OK;
} }
// Remove // Remove
TWO_KEY_AVL_TREE_TEMPLATE_LIST TWO_KEY_AVL_TREE_TEMPLATE_LIST
status_t status_t
TWO_KEY_AVL_TREE_CLASS_NAME::Remove(const PrimaryKey &primaryKey, TWO_KEY_AVL_TREE_CLASS_NAME::Remove(const PrimaryKey &primaryKey,
const SecondaryKey &secondaryKey) const SecondaryKey &secondaryKey)
{ {
return BaseClass::Remove(Key(primaryKey, secondaryKey)); return fTreeMap.Remove(Key(primaryKey, secondaryKey));
}
// Remove
TWO_KEY_AVL_TREE_TEMPLATE_LIST
void
TWO_KEY_AVL_TREE_CLASS_NAME::Remove(Iterator &iterator)
{
BaseClass::Remove(iterator);
} }
#endif // TWO_KEY_AVL_TREE_H #endif // TWO_KEY_AVL_TREE_H
@@ -81,10 +81,9 @@ public:
// NodeListenerTree // NodeListenerTree
typedef TwoKeyAVLTree<NodeListenerValue, Node*, typedef TwoKeyAVLTree<NodeListenerValue, Node*,
AVLTreeStandardCompare<Node*>, TwoKeyAVLTreeStandardCompare<Node*>,
NodeListenerGetPrimaryKey, NodeListener*, NodeListenerGetPrimaryKey, NodeListener*,
AVLTreeStandardNode<NodeListenerValue>, TwoKeyAVLTreeStandardCompare<NodeListener*>,
AVLTreeStandardCompare<NodeListener*>,
NodeListenerGetSecondaryKey > _NodeListenerTree; NodeListenerGetSecondaryKey > _NodeListenerTree;
class NodeListenerTree : public _NodeListenerTree {}; class NodeListenerTree : public _NodeListenerTree {};
@@ -118,10 +117,9 @@ public:
// EntryListenerTree // EntryListenerTree
typedef TwoKeyAVLTree<EntryListenerValue, Entry*, typedef TwoKeyAVLTree<EntryListenerValue, Entry*,
AVLTreeStandardCompare<Entry*>, TwoKeyAVLTreeStandardCompare<Entry*>,
EntryListenerGetPrimaryKey, EntryListener*, EntryListenerGetPrimaryKey, EntryListener*,
AVLTreeStandardNode<EntryListenerValue>, TwoKeyAVLTreeStandardCompare<EntryListener*>,
AVLTreeStandardCompare<EntryListener*>,
EntryListenerGetSecondaryKey > _EntryListenerTree; EntryListenerGetSecondaryKey > _EntryListenerTree;
class EntryListenerTree : public _EntryListenerTree {}; class EntryListenerTree : public _EntryListenerTree {};
@@ -57,6 +57,7 @@ const ino_t kRootParentID = 0;
// NodeListenerValue // NodeListenerValue
class NodeListenerValue { class NodeListenerValue {
public: public:
inline NodeListenerValue() {}
inline NodeListenerValue(int) {} inline NodeListenerValue(int) {}
inline NodeListenerValue(NodeListener *listener, Node *node, uint32 flags) inline NodeListenerValue(NodeListener *listener, Node *node, uint32 flags)
: listener(listener), node(node), flags(flags) {} : listener(listener), node(node), flags(flags) {}
@@ -73,6 +74,7 @@ typedef List<NodeListenerValue> NodeListenerList;
// EntryListenerValue // EntryListenerValue
class EntryListenerValue { class EntryListenerValue {
public: public:
inline EntryListenerValue() {}
inline EntryListenerValue(int) {} inline EntryListenerValue(int) {}
inline EntryListenerValue(EntryListener *listener, Entry *entry, inline EntryListenerValue(EntryListener *listener, Entry *entry,
uint32 flags) uint32 flags)