Skip to content

Commit

Permalink
TS-720: remove dependencies in STL, add new templated containers.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/trafficserver/traffic/trunk@1086420 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
John Bradley Plevyak committed Mar 28, 2011
1 parent 013f601 commit c324be7
Show file tree
Hide file tree
Showing 18 changed files with 2,381 additions and 73 deletions.
27 changes: 27 additions & 0 deletions LICENSE
Expand Up @@ -359,6 +359,33 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

~~~

Copyright (c) 1994-2011 John Bradley Plevyak, All Rights Reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

~~~

Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
Copyright (C) 2005 Ariya Hidayat (ariya@kde.org)
Expand Down
118 changes: 117 additions & 1 deletion lib/ts/List.h
Expand Up @@ -61,6 +61,7 @@
#include "ink_queue.h"
#include "ink_resource.h"
#include "Compatability.h"
#include "defalloc.h"

//
// Link cell for singly-linked list of objects of type C.
Expand Down Expand Up @@ -346,8 +347,123 @@ template<class C, class L = typename C::Link_link> struct SortableQueue: public
};
#define SortableQue(_c, _l) SortableQueue<_c, _c::Link##_##_f>

//
// Adds counting to the Queue
//

template <class C, class L = typename C::Link_link> struct CountQueue : public Queue<C,L> {
int size;
inline CountQueue(void) : size(0) {}
inline void push(C *e);
inline C *pop();
inline void enqueue(C *e);
inline C *dequeue();
inline void remove(C *e);
inline void insert(C *e, C *after);
inline void append(CountQueue<C,L> &q);
inline void append_clear(CountQueue<C,L> &q);
};
#define CountQue(_c, _f) CountQueue<_c, _c::Link##_##_f>
#define CountQueM(_c, _m, _mf, _f) CountQueue<_c, _c::Link##_##_mf##_##_f>

template <class C, class L> inline void
CountQueue<C,L>::push(C *e) {
Queue<C,L>::push(e);
size++;
}

template <class C, class L> inline C *
CountQueue<C,L>::pop() {
C *ret = Queue<C,L>::pop();
if (ret)
size--;
return ret;
}

template <class C, class L> inline void
CountQueue<C,L>::remove(C *e) {
Queue<C,L>::remove(e);
size--;
}

template <class C, class L> inline void
CountQueue<C,L>::enqueue(C *e) {
Queue<C,L>::enqueue(e);
size++;
}

template <class C, class L> inline C *
CountQueue<C,L>::dequeue() {
return pop();
}

// atomic lists
template <class C, class L> inline void
CountQueue<C,L>::insert(C *e, C *after) {
Queue<C,L>::insert(e, after);
size++;
}

template <class C, class L> inline void
CountQueue<C,L>::append(CountQueue<C,L> &q) {
Queue<C,L>::append(q);
size += q.size;
};

template <class C, class L> inline void
CountQueue<C,L>::append_clear(CountQueue<C,L> &q) {
append(q);
q.head = q.tail = 0;
q.size = 0;
}

//
// List using cons cells
//

template <class C, class A = DefaultAlloc>
struct ConsCell {
C car;
ConsCell *cdr;
ConsCell(C acar, ConsCell *acdr) : car(acar), cdr(acdr) {}
ConsCell(C acar) : car(acar), cdr(NULL) {}
ConsCell(ConsCell *acdr) : cdr(acdr) {}
static void *operator new(size_t size) { return A::alloc(size); }
static void operator delete(void *p, size_t size) { A::free(p); }
};

template <class C, class A = DefaultAlloc>
struct List {
ConsCell<C,A> *head;
C first() { if (head) return head->car; else return 0; }
C car() { return first(); }
ConsCell<C,A> *rest() { if (head) return head->cdr; else return 0; }
ConsCell<C,A> *cdr() { return rest(); }
void push(C a) { head = new ConsCell<C,A>(a, head); }
void push() { head = new ConsCell<C,A>(head); }
C pop() { C a = car(); head = cdr(); return a; }
void clear() { head = NULL; }
void reverse();
List(C acar) : head(new ConsCell<C,A>(acar)) {}
List(C a, C b) : head(new ConsCell<C,A>(a, new ConsCell<C,A>(b))) {}
List(C a, C b, C c) : head(new ConsCell<C,A>(a, new ConsCell<C,A>(b, new ConsCell<C,A>(c)))) {}
List() : head(0) {}
};
#define forc_List(_c, _p, _l) if ((_l).head) for (_c *_p = (_l).head; _p; _p = _p->cdr)

template <class C,class A> void
List<C,A>::reverse() {
ConsCell<C,A> *n, *t;
for (ConsCell<C,A> *p = head; p; p = n) {
n = p->cdr;
p->cdr = t;
t = p;
}
head = t;
}

//
// Atomic lists
//

template<class C, class L = typename C::Link_link> struct AtomicSLL
{
Expand Down
10 changes: 9 additions & 1 deletion lib/ts/Makefile.am
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.

noinst_PROGRAMS = mkdfa CompileParseRules
check_PROGRAMS = test_atomic test_freelist test_arena test_List
check_PROGRAMS = test_atomic test_freelist test_arena test_List test_Map test_Vec
TESTS = $(check_PROGRAMS)

lib_LTLIBRARIES = libtsutil.la
Expand All @@ -39,6 +39,7 @@ libtsutil_la_SOURCES = \
DynArray.h \
HostLookup.cc \
HostLookup.h \
defalloc.h \
ink_aiocb.h \
ink_align.h \
ink_apidefs.h \
Expand Down Expand Up @@ -143,6 +144,9 @@ libtsutil_la_SOURCES = \
TextBuffer.h \
Tokenizer.cc \
Tokenizer.h \
Vec.h \
Vec.cc \
Map.h \
Version.cc

# Special hacks to generate the parser rules
Expand All @@ -166,6 +170,10 @@ test_arena_LDADD = libtsutil.la @LIBTHREAD@ @LIBTCL@ @LIBICONV@ @LIBEXECINFO@
test_arena_LDFLAGS = @EXTRA_CXX_LDFLAGS@

test_List_SOURCES = test_List.cc
test_Map_SOURCES = test_Map.cc
test_Map_LDADD = libtsutil.la
test_Vec_SOURCES = test_Vec.cc
test_Vec_LDADD = libtsutil.la

CompileParseRules_SOURCES = CompileParseRules.cc

Expand Down

0 comments on commit c324be7

Please sign in to comment.