NEURON
htlist.cpp
Go to the documentation of this file.
1 #ifdef HAVE_CONFIG_H
2 #include <../../nrnconf.h>
3 #endif
4 /*
5 Based on Unidraw UList but UList changed to HTList (head tail list)
6 for fast insertion, deletion, iteration
7 */
8 
9 /*
10  * Copyright (c) 1990, 1991 Stanford University
11  *
12  * Permission to use, copy, modify, distribute, and sell this software and its
13  * documentation for any purpose is hereby granted without fee, provided
14  * that the above copyright notice appear in all copies and that both that
15  * copyright notice and this permission notice appear in supporting
16  * documentation, and that the name of Stanford not be used in advertising or
17  * publicity pertaining to distribution of the software without specific,
18  * written prior permission. Stanford makes no representations about
19  * the suitability of this software for any purpose. It is provided "as is"
20  * without express or implied warranty.
21  *
22  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
23  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
24  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
25  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
26  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
28  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29  */
30 
31 /*
32  * HTList implementation.
33  */
34 
35 #include <stdio.h>
36 #include <OS/enter-scope.h>
37 #include <htlist.h>
38 
39 /*****************************************************************************/
40 
41 HTList::HTList(void* p) {
42  _next = this;
43  _prev = this;
44  _object = p;
45 }
46 
48  HTList* next = _next;
49  if (next != this && next != NULL) {
50  Remove(this);
51  delete next;
52  }
53 }
54 
56  _prev->_next = e;
57  e->_prev = _prev;
58  e->_next = this;
59  _prev = e;
60 }
61 
63  _next->_prev = e;
64  e->_prev = this;
65  e->_next = _next;
66  _next = e;
67 }
68 
70  e->_prev->_next = e->_next;
71  e->_next->_prev = e->_prev;
72  e->_prev = e->_next = NULL;
73 }
74 
76  if (_prev) {
77  _prev->_next = _next;
78  }
79  if (_next) {
80  _next->_prev = _prev;
81  }
82  _prev = _next = NULL;
83 }
85  while (!IsEmpty()) {
86  Remove(First());
87  }
88 }
89 void HTList::Delete(void* p) {
90  HTList* e;
91 
92  e = Find(p);
93  if (e != NULL) {
94  Remove(e);
95  delete e;
96  }
97 }
98 
100  HTList* e;
101 
102  for (e = _next; e != this; e = e->_next) {
103  if (e->_object == p) {
104  return e;
105  }
106  }
107  return NULL;
108 }
109 
111  HTList* pos = First();
112  int i;
113 
114  for (i = 1; i < count && pos != End(); ++i) {
115  pos = pos->Next();
116  }
117  if (i == count) {
118  return pos;
119  }
120  return NULL;
121 }
Definition: htlist.h:34
void Remove()
Definition: htlist.cpp:75
HTList * Find(void *)
Definition: htlist.cpp:99
void * _object
Definition: htlist.h:58
void Prepend(HTList *)
Definition: htlist.cpp:62
bool IsEmpty()
Definition: htlist.h:63
HTList * First()
Definition: htlist.h:66
virtual ~HTList()
Definition: htlist.cpp:47
HTList * Next()
Definition: htlist.h:75
HTList(void *=NULL)
Definition: htlist.cpp:41
void Append(HTList *)
Definition: htlist.cpp:55
HTList * _next
Definition: htlist.h:59
HTList * _prev
Definition: htlist.h:60
HTList * operator[](int count)
Definition: htlist.cpp:110
HTList * End()
Definition: htlist.h:72
void RemoveAll()
Definition: htlist.cpp:84
void Delete(void *)
Definition: htlist.cpp:89
#define i
Definition: md1redef.h:19
Item * next(Item *item)
Definition: list.cpp:89
size_t p
#define NULL
Definition: spdefs.h:105