* Added RemoveTail() method.

* Renamed DoublyLinkedList::Size() to Count(), since it actually counts the
  items (ie. O(n)).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29979 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-04-06 21:06:19 +00:00
parent f9ae64e9a5
commit fd0803f300
6 changed files with 105 additions and 92 deletions
+17 -4
View File
@@ -1,5 +1,7 @@
/* /*
* Copyright 2005-2007, Ingo Weinhold, [email protected]. All rights reserved. * Copyright 2005-2007, Ingo Weinhold, [email protected].
* Copyright 2006-2009, Axel Dörfler, [email protected].
*
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef KERNEL_UTIL_DOUBLY_LINKED_LIST_H #ifndef KERNEL_UTIL_DOUBLY_LINKED_LIST_H
@@ -354,11 +356,12 @@ public:
inline Element* Tail() const { return fLast; } inline Element* Tail() const { return fLast; }
inline Element* RemoveHead(); inline Element* RemoveHead();
inline Element* RemoveTail();
inline Element* GetPrevious(Element* element) const; inline Element* GetPrevious(Element* element) const;
inline Element* GetNext(Element* element) const; inline Element* GetNext(Element* element) const;
inline int32 Size() const; inline int32 Count() const;
// O(n)! // O(n)!
inline Iterator GetIterator() { return Iterator(this); } inline Iterator GetIterator() { return Iterator(this); }
@@ -546,6 +549,16 @@ DOUBLY_LINKED_LIST_CLASS_NAME::RemoveHead()
return element; return element;
} }
// RemoveTail
DOUBLY_LINKED_LIST_TEMPLATE_LIST
Element*
DOUBLY_LINKED_LIST_CLASS_NAME::RemoveTail()
{
Element* element = Tail();
Remove(element);
return element;
}
// GetPrevious // GetPrevious
DOUBLY_LINKED_LIST_TEMPLATE_LIST DOUBLY_LINKED_LIST_TEMPLATE_LIST
Element* Element*
@@ -568,10 +581,10 @@ DOUBLY_LINKED_LIST_CLASS_NAME::GetNext(Element *element) const
return result; return result;
} }
// Size // Count
DOUBLY_LINKED_LIST_TEMPLATE_LIST DOUBLY_LINKED_LIST_TEMPLATE_LIST
int32 int32
DOUBLY_LINKED_LIST_CLASS_NAME::Size() const DOUBLY_LINKED_LIST_CLASS_NAME::Count() const
{ {
int32 count = 0; int32 count = 0;
for (Element* element = First(); element; element = GetNext(element)) for (Element* element = First(); element; element = GetNext(element))
@@ -120,7 +120,7 @@ void
BasicThreadProfileResult::PrintResults() BasicThreadProfileResult::PrintResults()
{ {
// get hit images // get hit images
BasicThreadImage* images[fOldImages.Size() + fImages.Size()]; BasicThreadImage* images[fOldImages.Count() + fImages.Count()];
int32 imageCount = GetHitImages(images); int32 imageCount = GetHitImages(images);
// count symbols // count symbols
@@ -204,7 +204,7 @@ CallgrindThreadProfileResult::PrintResults()
fprintf(out, "summary: %lld %lld\n", fTotalTicks, fTotalTicks * fInterval); fprintf(out, "summary: %lld %lld\n", fTotalTicks, fTotalTicks * fInterval);
// get hit images // get hit images
CallgrindThreadImage* images[fOldImages.Size() + fImages.Size()]; CallgrindThreadImage* images[fOldImages.Count() + fImages.Count()];
int32 imageCount = GetHitImages(images); int32 imageCount = GetHitImages(images);
for (int32 i = 0; i < imageCount; i++) { for (int32 i = 0; i < imageCount; i++) {
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2008, Axel Dörfler, [email protected]. * Copyright 2004-2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -1523,7 +1523,7 @@ dump_cache(int argc, char** argv)
kprintf(" %ld blocks total, %ld dirty, %ld discarded, %ld referenced, %ld " kprintf(" %ld blocks total, %ld dirty, %ld discarded, %ld referenced, %ld "
"in unused.\n", count, dirty, discarded, referenced, "in unused.\n", count, dirty, discarded, referenced,
cache->unused_blocks.Size()); cache->unused_blocks.Count());
hash_close(cache->hash, &iterator, false); hash_close(cache->hash, &iterator, false);
return 0; return 0;
+1 -1
View File
@@ -264,7 +264,7 @@ ConditionVariable::ListAll()
ConditionVariableHash::Iterator it(&sConditionVariableHash); ConditionVariableHash::Iterator it(&sConditionVariableHash);
while (ConditionVariable* variable = it.Next()) { while (ConditionVariable* variable = it.Next()) {
// count waiting threads // count waiting threads
int count = variable->fEntries.Size(); int count = variable->fEntries.Count();
kprintf("%p %p %-20s %15d\n", variable, variable->fObject, kprintf("%p %p %-20s %15d\n", variable, variable->fObject,
variable->fObjectType, count); variable->fObjectType, count);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -723,7 +723,7 @@ dump_driver(int argc, char** argv)
kprintf("%p %5ld %3ld %5ld %c %3ld %s\n", driver, kprintf("%p %5ld %3ld %5ld %c %3ld %s\n", driver,
driver->image < 0 ? -1 : driver->image, driver->image < 0 ? -1 : driver->image,
driver->devices_used, driver->devices.Size(), driver->devices_used, driver->devices.Count(),
driver->binary_updated ? 'U' : ' ', driver->priority, driver->binary_updated ? 'U' : ' ', driver->priority,
driver->name); driver->name);
} }
@@ -751,7 +751,7 @@ dump_driver(int argc, char** argv)
kprintf(" node: %Ld\n", driver->node); kprintf(" node: %Ld\n", driver->node);
kprintf(" last modified: %ld\n", driver->last_modified); kprintf(" last modified: %ld\n", driver->last_modified);
kprintf(" devs used: %ld\n", driver->devices_used); kprintf(" devs used: %ld\n", driver->devices_used);
kprintf(" devs published: %ld\n", driver->devices.Size()); kprintf(" devs published: %ld\n", driver->devices.Count());
kprintf(" binary updated: %d\n", driver->binary_updated); kprintf(" binary updated: %d\n", driver->binary_updated);
kprintf(" priority: %ld\n", driver->priority); kprintf(" priority: %ld\n", driver->priority);
kprintf(" api version: %ld\n", driver->api_version); kprintf(" api version: %ld\n", driver->api_version);