* BinaryInsertUnique() didn't work at all.
* both, BinaryInsert() and BinaryInsertUnique() now propagate the result of the AddItem() call - which could fail because of low memory. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14825 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -198,9 +198,9 @@ public:
|
||||
// these to work
|
||||
|
||||
// simple insert
|
||||
void BinaryInsert(T *, CompareFunction);
|
||||
void BinaryInsert(T *, CompareFunctionWithState, void *state);
|
||||
void BinaryInsert(T *, const UnaryPredicate<T> &);
|
||||
bool BinaryInsert(T *, CompareFunction);
|
||||
bool BinaryInsert(T *, CompareFunctionWithState, void *state);
|
||||
bool BinaryInsert(T *, const UnaryPredicate<T> &);
|
||||
|
||||
// unique insert, returns false if item already in list
|
||||
bool BinaryInsertUnique(T *, CompareFunction);
|
||||
@@ -216,7 +216,6 @@ public:
|
||||
T *BinaryInsertCopyUnique(const T ©This, CompareFunction);
|
||||
T *BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState, void *state);
|
||||
|
||||
|
||||
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool *alreadyInList = 0) const;
|
||||
// returns either the index into which a new item should be inserted
|
||||
// or index of an existing item that matches the predicate
|
||||
@@ -399,7 +398,6 @@ BObjectList<T>::~BObjectList()
|
||||
if (Owning())
|
||||
// have to nuke elements first
|
||||
MakeEmpty();
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -641,55 +639,55 @@ BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
bool
|
||||
BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunction)func);
|
||||
if (index >= 0)
|
||||
if (index >= 0) {
|
||||
// already in list, add after existing
|
||||
AddItem(item, index + 1);
|
||||
else
|
||||
AddItem(item, -index - 1);
|
||||
}
|
||||
return AddItem(item, index + 1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
if (index >= 0)
|
||||
// already in list, add after existing
|
||||
AddItem(item, index + 1);
|
||||
else
|
||||
AddItem(item, -index - 1);
|
||||
return AddItem(item, -index - 1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::BinaryInsertUnique(T *, CompareFunction func)
|
||||
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
if (index >= 0) {
|
||||
// already in list, add after existing
|
||||
return AddItem(item, index + 1);
|
||||
}
|
||||
|
||||
return AddItem(item, -index - 1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunction)func);
|
||||
if (index >= 0)
|
||||
return false;
|
||||
|
||||
AddItem(item, -index - 1);
|
||||
return true;
|
||||
return AddItem(item, -index - 1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::BinaryInsertUnique(T *, CompareFunctionWithState func, void *state)
|
||||
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
if (index >= 0)
|
||||
return false;
|
||||
|
||||
AddItem(item, -index - 1);
|
||||
return true;
|
||||
return AddItem(item, -index - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -776,11 +774,10 @@ BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *al
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
bool
|
||||
BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred)
|
||||
{
|
||||
int32 index = FindBinaryInsertionIndex(pred);
|
||||
AddItem(item, index);
|
||||
return AddItem(item, FindBinaryInsertionIndex(pred));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -796,5 +793,4 @@ BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif /* __OBJECT_LIST__ */
|
||||
|
||||
Reference in New Issue
Block a user