]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - include/CbDataList.h
SourceFormat Enforcement
[thirdparty/squid.git] / include / CbDataList.h
index 79dcfef618eec2b86e13641934707cea46ed1bab..a7376416e25ccfa840715374bd41c1b7edf37ef5 100644 (file)
@@ -1,7 +1,4 @@
 /*
- * $Id: List.h,v 1.8 2008/02/26 21:49:33 amosjeffries Exp $
- *
- *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
  * ----------------------------------------------------------
  *
@@ -47,8 +44,14 @@ public:
     CbDataList (C const &);
     ~CbDataList();
 
+    /// If element is already in the list, returns false.
+    /// Otherwise, adds the element to the end of the list and returns true.
+    /// Exists to avoid double iteration of find() and push() combo.
+    bool push_back_unique(C const &element);
     bool find(C const &)const;
     bool findAndTune(C const &);
+    /// Iterates the entire list to return the last element holder.
+    CbDataList *tail();
     CbDataList *next;
     C element;
     bool empty() const { return this == NULL; }
@@ -128,6 +131,29 @@ CbDataList<C>::~CbDataList()
         delete next;
 }
 
+template <class C>
+bool
+CbDataList<C>::push_back_unique(C const &toAdd)
+{
+    CbDataList<C> *last;
+    for (last = this; last->next; last = last->next) {
+        if (last->element == toAdd)
+            return false;
+    }
+
+    last->next = new CbDataList<C>(toAdd);
+    return true;
+}
+
+template <class C>
+CbDataList<C> *
+CbDataList<C>::tail()
+{
+    CbDataList<C> *last;
+    for (last = this; last->next; last = last->next);
+    return last;
+}
+
 template <class C>
 bool
 CbDataList<C>::find (C const &toFind) const