/*
- * $Id: splay.h,v 1.19 2003/06/09 03:39:08 robertc Exp $
+ * $Id: splay.h,v 1.20 2003/06/24 12:30:59 robertc Exp $
*/
#ifndef SQUID_SPLAY_H
mutable SplayNode<V> *right;
void destroy(SPLAYFREE *);
void walk(SPLAYWALKEE *, void *callerState);
+ SplayNode<V> const * start() const;
SplayNode<V> * remove(const Value data, SPLAYCMP * compare);
SplayNode<V> * insert(Value data, SPLAYCMP * compare);
SplayNode<V> * splay(const Value &data, SPLAYCMP * compare) const;
Value const *find (Value const &, SPLAYCMP *compare) const;
void insert(Value const &, SPLAYCMP *compare);
void remove(Value const &, SPLAYCMP *compare);
+ SplayNode<V> const * start() const;
size_t elements;
};
right->walk(walkee, state);
}
+template<class V>
+SplayNode<V> const *
+SplayNode<V>::start() const
+{
+ if (this && left)
+ return left->start();
+ return this;
+}
+
template<class V>
void
SplayNode<V>::destroy(SPLAYFREE * free_func)
--elements;
}
+template <class V>
+SplayNode<V> const *
+Splay<V>:: start() const{
+ if (head)
+ return head->start();
+ return NULL;
+}
+
#endif
#endif /* SQUID_SPLAY_H */
/*
- * $Id: MemObject.cc,v 1.6 2003/03/04 01:40:25 robertc Exp $
+ * $Id: MemObject.cc,v 1.7 2003/06/24 12:30:59 robertc Exp $
*
* DEBUG: section 19 Store Memory Primitives
* AUTHOR: Robert Collins
bool
MemObject::isContiguous() const
{
- bool result = data_hdr.hasContigousContentRange (inmem_lo, endOffset());
+ bool result = data_hdr.hasContigousContentRange (Range<size_t>(inmem_lo, endOffset()));
/* XXX : make this higher level */
debug (19, result ? 4 :3) ("MemObject::isContiguous: Returning %s\n",
result ? "true" : "false");
/*
- * $Id: mem_node.cc,v 1.2 2003/02/21 22:50:10 robertc Exp $
+ * $Id: mem_node.cc,v 1.3 2003/06/24 12:30:59 robertc Exp $
*
* DEBUG: section 19 Store Memory Primitives
* AUTHOR: Robert Collins
return false;
}
+
+bool
+mem_node::operator < (mem_node const & rhs) const
+{
+ return start() < rhs.start();
+}
/*
- * $Id: mem_node.h,v 1.2 2003/02/21 22:50:10 robertc Exp $
+ * $Id: mem_node.h,v 1.3 2003/06/24 12:30:59 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
size_t end() const;
bool contains (size_t const &location) const;
bool canAccept (size_t const &location) const;
+ bool operator < (mem_node const & rhs) const;
/* public */
StoreIOBuffer nodeBuffer;
mem_node *next;
/*
- * $Id: stmem.cc,v 1.76 2003/02/21 22:50:11 robertc Exp $
+ * $Id: stmem.cc,v 1.77 2003/06/24 12:30:59 robertc Exp $
*
* DEBUG: section 19 Store Memory Primitives
* AUTHOR: Harvest Derived
if (!pointer) {
/* prepend to list */
aNode->next = head;
- head = aNode->next;
+ head = aNode;
} else {
/* Append it to existing chain */
aNode->next = pointer->next;
}
bool
-mem_hdr::hasContigousContentRange(size_t start, size_t end) const
+mem_hdr::hasContigousContentRange(Range<size_t> const & range) const
{
- size_t currentStart = start;
+ size_t currentStart = range.start;
while (mem_node *curr = getBlockContainingLocation(currentStart)) {
currentStart = curr->end();
- if (currentStart >= end)
+ if (currentStart >= range.end)
return true;
}
/* case 2: location fits within an extant node */
mem_node *candidate = getHighestBlockBeforeLocation(offset);
- /* case 2: no nodes before it */
+ /* case 3: no nodes before it */
if (!candidate) {
candidate = new mem_node(offset);
appendNode (candidate);
return true;
}
+
+mem_hdr::mem_hdr() : head (NULL), tail(NULL), inmem_hi(0)
+{}
+
+mem_hdr::~mem_hdr()
+{
+ freeContent();
+}
/*
- * $Id: stmem.h,v 1.2 2003/02/21 22:50:11 robertc Exp $
+ * $Id: stmem.h,v 1.3 2003/06/24 12:30:59 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
#ifndef SQUID_STMEM_H
#define SQUID_STMEM_H
+#include "splay.h"
+#include "Range.h"
+
class mem_node;
class StoreIOBuffer;
{
public:
+ mem_hdr();
+ ~mem_hdr();
void freeContent();
int lowestOffset () const;
off_t endOffset () const;
int freeDataUpto (int);
ssize_t copy (off_t, char *, size_t) const;
- bool hasContigousContentRange(size_t start, size_t end) const;
+ bool hasContigousContentRange(Range<size_t> const &range) const;
/* success or fail */
bool write (StoreIOBuffer const &);
mem_node *nodeToRecieve(off_t offset);
size_t writeAvailable(mem_node *aNode, size_t location, size_t amount, char const *source);
off_t inmem_hi;
+ Splay<mem_node> nodes;
};
#endif /* SQUID_STMEM_H */
#
# Makefile for the Squid Object Cache server
#
-# $Id: Makefile.am,v 1.7 2003/06/22 08:04:28 robertc Exp $
+# $Id: Makefile.am,v 1.8 2003/06/24 12:31:00 robertc Exp $
#
AUTOMAKE_OPTIONS = subdir-objects
TESTS = rfc1738 \
refcount\
splay\
- mem_node_test\
MemPoolTest\
+ mem_node_test\
+ mem_hdr_test\
http_range_test
-## Sort by dependencies - test lowest layers first
-check_PROGRAMS= rfc1738\
- refcount\
- splay\
+## Sort by alpha - any build failures are significant.
+check_PROGRAMS= http_range_test \
MemPoolTest\
mem_node_test\
- http_range_test
+ mem_hdr_test \
+ refcount\
+ rfc1738\
+ splay
LDADD = -L$(top_builddir)/lib -lmiscutil
mem_node_test_SOURCES = mem_node_test.cc
mem_node_test_LDADD = $(top_builddir)/src/mem_node.o $(LDADD)
+mem_hdr_test_SOURCES = mem_hdr_test.cc test_tools.cc
+mem_hdr_test_LDADD = $(top_builddir)/src/stmem.o \
+ $(top_builddir)/src/mem_node.o $(LDADD)
MemPoolTest_SOURCES = MemPoolTest.cc
refcount_SOURCES = refcount.cc
--- /dev/null
+
+/*
+ * $Id: mem_hdr_test.cc,v 1.1 2003/06/24 12:31:02 robertc Exp $
+ *
+ * DEBUG: section 19 Store Memory Primitives
+ * AUTHOR: Robert Collins
+ *
+ * SQUID Web Proxy Cache http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ * Squid is the result of efforts by numerous individuals from
+ * the Internet community; see the CONTRIBUTORS file for full
+ * details. Many organizations have provided support for Squid's
+ * development; see the SPONSORS file for full details. Squid is
+ * Copyrighted (C) 2001 by the Regents of the University of
+ * California; see the COPYRIGHT file for full details. Squid
+ * incorporates software developed and/or copyrighted by other
+ * sources; see the CREDITS file for full details.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
+ */
+
+#include "squid.h"
+#include "stmem.h"
+#include "mem_node.h"
+#include <iostream>
+
+void
+testLowAndHigh()
+{
+ mem_hdr aHeader;
+ assert (aHeader.lowestOffset() == 0);
+ assert (aHeader.write (StoreIOBuffer()));
+ assert (aHeader.lowestOffset() == 0);
+ assert (aHeader.write (StoreIOBuffer(0, 1, NULL)));
+ assert (aHeader.lowestOffset() == 0);
+ char * sampleData = xstrdup ("A");
+ assert (aHeader.write (StoreIOBuffer(1, 100, sampleData)));
+ safe_free (sampleData);
+ assert (aHeader.lowestOffset() == 100);
+ assert (aHeader.endOffset() == 101);
+ sampleData = xstrdup ("B");
+ assert (aHeader.write (StoreIOBuffer(1, 10, sampleData)));
+ safe_free (sampleData);
+ assert (aHeader.lowestOffset() == 10);
+ assert (aHeader.endOffset() == 101);
+ assert (aHeader.hasContigousContentRange(Range<size_t>(10,11)));
+ assert (!aHeader.hasContigousContentRange(Range<size_t>(10,12)));
+ assert (!aHeader.hasContigousContentRange(Range<size_t>(10,101)));
+}
+
+int
+main (int argc, char *argv)
+{
+ testLowAndHigh();
+ assert (mem_node::InUseCount() == 0);
+ return 0;
+}
/*
- * $Id: mem_node_test.cc,v 1.2 2003/06/23 20:53:47 robertc Exp $
+ * $Id: mem_node_test.cc,v 1.3 2003/06/24 12:31:00 robertc Exp $
*
* DEBUG: section 19 Store Memory Primitives
* AUTHOR: Robert Collins
aNode->nodeBuffer.length = SM_PAGE_SIZE - 1;
assert (aNode->canAccept (50 + SM_PAGE_SIZE - 1));
assert (!aNode->canAccept (50 + SM_PAGE_SIZE));
+ assert (mem_node (0) < mem_node (2));
+ assert (!(mem_node (0) < mem_node (0)));
+ assert (!(mem_node (2) < mem_node (0)));
return 0;
}
/*
- * $Id: splay.cc,v 1.3 2003/04/22 01:37:44 robertc Exp $
+ * $Id: splay.cc,v 1.4 2003/06/24 12:31:00 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
SplayCheck::BeginWalk();
intnode I;
I.i = 1;
+ /* check we don't segfault on NULL splay calls */
SplayCheck::WalkNodeRef(I, NULL);
I.i = 0;
SplayCheck::ExpectedFail = true;
SplayCheck::WalkNodeRef(I, NULL);
+
+{
+ /* check for begin() */
+ SplayNode<intnode> *safeTop = NULL;
+ if (safeTop->start() != NULL)
+ exit (1);
+ for (int i = 0; i < 100; i++) {
+ intnode I;
+ I.i = random();
+ if (i > 50)
+ safeTop = safeTop->insert(I, compareintref);
+ }
+ {
+ intnode I;
+ I.i = 50;
+ safeTop = safeTop->insert (I, compareintref);
+ }
+ if (!safeTop->start())
+ exit (1);
+ if (safeTop->start()->data.i != 50)
+ exit (1);
+ safeTop->destroy(destintref);
+}
+ {
+ Splay<intnode *> aSplay;
+ if (aSplay.start() != NULL)
+ exit (1);
+ }
return 0;
}
--- /dev/null
+
+/*
+ * $Id: test_tools.cc,v 1.1 2003/06/24 12:31:02 robertc Exp $
+ *
+ * AUTHOR: Robert Collins
+ *
+ * SQUID Web Proxy Cache http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ * Squid is the result of efforts by numerous individuals from
+ * the Internet community; see the CONTRIBUTORS file for full
+ * details. Many organizations have provided support for Squid's
+ * development; see the SPONSORS file for full details. Squid is
+ * Copyrighted (C) 2001 by the Regents of the University of
+ * California; see the COPYRIGHT file for full details. Squid
+ * incorporates software developed and/or copyrighted by other
+ * sources; see the CREDITS file for full details.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
+ */
+
+#include "squid.h"
+#include <iostream>
+
+void
+xassert(const char *msg, const char *file, int line)
+{
+ std::cout << "Assertion failed: (" << msg << ") at " << file << ":" << line << std::endl;
+ exit (1);
+}
+time_t squid_curtime = 0;
+
+int Debug::Levels[MAX_DEBUG_SECTIONS];
+int Debug::level;
+
+static void
+_db_print_stderr(const char *format, va_list args);
+
+void
+#if STDC_HEADERS
+_db_print(const char *format,...)
+{
+#else
+_db_print(va_alist)
+va_dcl
+{
+ const char *format = NULL;
+#endif
+
+ LOCAL_ARRAY(char, f, BUFSIZ);
+ va_list args1;
+#if STDC_HEADERS
+
+ va_list args2;
+ va_list args3;
+#else
+#define args2 args1
+#define args3 args1
+#endif
+
+#if STDC_HEADERS
+
+ va_start(args1, format);
+
+ va_start(args2, format);
+
+ va_start(args3, format);
+
+#else
+
+ format = va_arg(args1, const char *);
+
+#endif
+
+ snprintf(f, BUFSIZ, "%s| %s",
+ "stub time", //debugLogTime(squid_curtime),
+ format);
+
+ _db_print_stderr(f, args2);
+
+ va_end(args1);
+
+#if STDC_HEADERS
+
+ va_end(args2);
+
+ va_end(args3);
+
+#endif
+}
+
+static void
+_db_print_stderr(const char *format, va_list args) {
+ /* FIXME? */
+ // if (opt_debug_stderr < Debug::level)
+ if (1 < Debug::level)
+ return;
+
+ vfprintf(stderr, format, args);
+}
+
+void
+fatal(const char *message) {
+ debug (0,0) ("Fatal: %s",message);
+ exit (1);
+}