From: robertc <> Date: Mon, 22 Sep 2003 09:31:02 +0000 (+0000) Subject: Summary: Fix iterator-conflict in the name Splay::end X-Git-Tag: SQUID_3_0_PRE4~1200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccd330845309b906a854ec3e48fa6c52458611cc;p=thirdparty%2Fsquid.git Summary: Fix iterator-conflict in the name Splay::end Keywords: Fix iterator-conflict in the name Splay::end --- diff --git a/include/splay.h b/include/splay.h index bec5f20ba5..dfc46ddd46 100644 --- a/include/splay.h +++ b/include/splay.h @@ -1,5 +1,5 @@ /* - * $Id: splay.h,v 1.24 2003/09/02 22:57:00 robertc Exp $ + * $Id: splay.h,v 1.25 2003/09/22 03:31:03 robertc Exp $ */ #ifndef SQUID_SPLAY_H @@ -51,7 +51,7 @@ public: void destroy(SPLAYFREE *); void walk(SPLAYWALKEE *, void *callerState); SplayNode const * start() const; - SplayNode const * end() const; + SplayNode const * finish() const; SplayNode * remove (const Value data, SPLAYCMP * compare); @@ -65,6 +65,10 @@ typedef SplayNode splayNode; template +class SplayIterator; + +template + class Splay { @@ -85,7 +89,7 @@ public: SplayNode const * start() const; - SplayNode const * end() const; + SplayNode const * finish() const; size_t size() const; @@ -137,10 +141,10 @@ SplayNode::start() const template SplayNode const * -SplayNode::end() const +SplayNode::finish() const { if (this && right) - return right->end(); + return right->finish(); return this; } @@ -338,10 +342,10 @@ Splay:: start() const template SplayNode const * -Splay:: end() const +Splay:: finish() const { if (head) - return head->end(); + return head->finish(); return NULL; } diff --git a/src/stmem.h b/src/stmem.h index b47fff8a29..4a99351501 100644 --- a/src/stmem.h +++ b/src/stmem.h @@ -1,6 +1,6 @@ /* - * $Id: stmem.h,v 1.4 2003/06/26 12:51:57 robertc Exp $ + * $Id: stmem.h,v 1.5 2003/09/22 03:31:03 robertc Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -61,6 +61,10 @@ public: /* Not an iterator - thus the start, not begin() */ mem_node const *start() const; mem_node *getBlockContainingLocation (size_t location) const; + /* access the contained nodes - easier than punning + * as a contianer ourselves + */ + const Splay &getNodes() const; /* Only for use of MemObject */ void internalAppend(const char *data, int len); diff --git a/test-suite/mem_hdr_test.cc b/test-suite/mem_hdr_test.cc index 1388d0a896..ae950d977a 100644 --- a/test-suite/mem_hdr_test.cc +++ b/test-suite/mem_hdr_test.cc @@ -1,6 +1,6 @@ /* - * $Id: mem_hdr_test.cc,v 1.3 2003/09/22 02:43:11 robertc Exp $ + * $Id: mem_hdr_test.cc,v 1.4 2003/09/22 03:31:02 robertc Exp $ * * DEBUG: section 19 Store Memory Primitives * AUTHOR: Robert Collins @@ -38,6 +38,7 @@ #include "stmem.h" #include "mem_node.h" #include +#include "Generic.h" void testLowAndHigh() @@ -72,14 +73,14 @@ testSplayOfNodes() temp5->nodeBuffer.length = 10; aSplay.insert (temp5, mem_hdr::NodeCompare); assert (aSplay.start()->data == temp5); - assert (aSplay.end()->data == temp5); + assert (aSplay.finish()->data == temp5); mem_node *temp0; temp0 = new mem_node(0); temp0->nodeBuffer.length = 5; aSplay.insert (temp0, mem_hdr::NodeCompare); assert (aSplay.start()->data == temp0); - assert (aSplay.end()->data == temp5); + assert (aSplay.finish()->data == temp5); mem_node *temp14; temp14 = new mem_node (14); @@ -94,6 +95,29 @@ testSplayOfNodes() aSplay.destroy(SplayNode::DefaultFree); } +struct mem_node_print +{ + mem_node_print(std::ostream &astream) : os(astream) {} + + void operator () (mem_node *aNode) + {} + + std::ostream &os; +}; + +void +testHdrVisit() +{ + mem_hdr aHeader; + char * sampleData = xstrdup ("A"); + assert (aHeader.write (StoreIOBuffer(1, 100, sampleData))); + safe_free (sampleData); + sampleData = xstrdup ("B"); + assert (aHeader.write (StoreIOBuffer(1, 102, sampleData))); + safe_free (sampleData); + //for_each (aHeader.getNodes().begin(). aHeader.getNodes().end(), mem_node_print(std::cout)); +} + int main (int argc, char *argv) { @@ -102,5 +126,7 @@ main (int argc, char *argv) assert (mem_node::InUseCount() == 0); testSplayOfNodes(); assert (mem_node::InUseCount() == 0); + testHdrVisit(); + assert (mem_node::InUseCount() == 0); return 0; } diff --git a/test-suite/splay.cc b/test-suite/splay.cc index cf5761f036..0ee0613b86 100644 --- a/test-suite/splay.cc +++ b/test-suite/splay.cc @@ -1,5 +1,5 @@ /* - * $Id: splay.cc,v 1.5 2003/06/26 12:52:00 robertc Exp $ + * $Id: splay.cc,v 1.6 2003/09/22 03:31:02 robertc Exp $ * * based on ftp://ftp.cs.cmu.edu/user/sleator/splaying/top-down-splay.c * http://bobo.link.cs.cmu.edu/cgi-bin/splay/splay-cgi.pl @@ -214,7 +214,7 @@ main(int argc, char *argv[]) if (safeTop->start() != NULL) exit (1); - if (safeTop->end() != NULL) + if (safeTop->finish() != NULL) exit (1); for (int i = 0; i < 100; i++) { @@ -239,10 +239,10 @@ main(int argc, char *argv[]) if (safeTop->start()->data.i != 50) exit (1); - if (!safeTop->end()) + if (!safeTop->finish()) exit (1); - if (safeTop->end()->data.i != 10000000) + if (safeTop->finish()->data.i != 10000000) exit (1); safeTop->destroy(destintref);