]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - include/CbDataList.h
SourceFormat Enforcement
[thirdparty/squid.git] / include / CbDataList.h
index f11105b80cec51ca07b7064411dffff5eee534b0..a7376416e25ccfa840715374bd41c1b7edf37ef5 100644 (file)
@@ -44,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; }
@@ -125,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