/*
- * $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
void destroy(SPLAYFREE *);
void walk(SPLAYWALKEE *, void *callerState);
SplayNode<V> const * start() const;
- SplayNode<V> const * end() const;
+ SplayNode<V> const * finish() const;
SplayNode<V> * remove
(const Value data, SPLAYCMP * compare);
template <class V>
+class SplayIterator;
+
+template <class V>
+
class Splay
{
SplayNode<V> const * start() const;
- SplayNode<V> const * end() const;
+ SplayNode<V> const * finish() const;
size_t size() const;
template<class V>
SplayNode<V> const *
-SplayNode<V>::end() const
+SplayNode<V>::finish() const
{
if (this && right)
- return right->end();
+ return right->finish();
return this;
}
template <class V>
SplayNode<V> const *
-Splay<V>:: end() const
+Splay<V>:: finish() const
{
if (head)
- return head->end();
+ return head->finish();
return NULL;
}
/*
- * $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/
/* 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<mem_node *> &getNodes() const;
/* Only for use of MemObject */
void internalAppend(const char *data, int len);
/*
- * $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
#include "stmem.h"
#include "mem_node.h"
#include <iostream>
+#include "Generic.h"
void
testLowAndHigh()
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);
aSplay.destroy(SplayNode<mem_node *>::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)
{
assert (mem_node::InUseCount() == 0);
testSplayOfNodes();
assert (mem_node::InUseCount() == 0);
+ testHdrVisit();
+ assert (mem_node::InUseCount() == 0);
return 0;
}
/*
- * $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
if (safeTop->start() != NULL)
exit (1);
- if (safeTop->end() != NULL)
+ if (safeTop->finish() != NULL)
exit (1);
for (int i = 0; i < 100; i++) {
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);