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) { _next = this; _prev = this; _object = p; }
42 
44  HTList* next = _next;
45  if (next != this && next != NULL) {
46  Remove(this);
47  delete next;
48  }
49 }
50 
52  _prev->_next = e;
53  e->_prev = _prev;
54  e->_next = this;
55  _prev = e;
56 }
57 
59  _next->_prev = e;
60  e->_prev = this;
61  e->_next = _next;
62  _next = e;
63 }
64 
66  e->_prev->_next = e->_next;
67  e->_next->_prev = e->_prev;
68  e->_prev = e->_next = NULL;
69 }
70 
72  if (_prev) { _prev->_next = _next; }
73  if (_next) { _next->_prev = _prev; }
74  _prev = _next = NULL;
75 }
77  while(!IsEmpty()) {
78  Remove(First());
79  }
80 }
81 void HTList::Delete (void* p) {
82  HTList* e;
83 
84  e = Find(p);
85  if (e != NULL) {
86  Remove(e);
87  delete e;
88  }
89 }
90 
91 HTList* HTList::Find (void* p) {
92  HTList* e;
93 
94  for (e = _next; e != this; e = e->_next) {
95  if (e->_object == p) {
96  return e;
97  }
98  }
99  return NULL;
100 }
101 
103  HTList* pos = First();
104  int i;
105 
106  for (i = 1; i < count && pos != End(); ++i) {
107  pos = pos->Next();
108  }
109  if (i == count) {
110  return pos;
111  }
112  return NULL;
113 }
HTList * Next()
Definition: htlist.h:67
HTList * End()
Definition: htlist.h:66
HTList(void *=NULL)
Definition: htlist.cpp:41
void Delete(void *)
Definition: htlist.cpp:81
size_t p
HTList * Find(void *)
Definition: htlist.cpp:91
Item * next(Item *item)
Definition: list.cpp:95
#define e
Definition: passive0.cpp:24
HTList * First()
Definition: htlist.h:64
HTList * _next
Definition: htlist.h:59
virtual ~HTList()
Definition: htlist.cpp:43
void Remove()
Definition: htlist.cpp:71
HTList * _prev
Definition: htlist.h:60
void * _object
Definition: htlist.h:58
HTList * operator[](int count)
Definition: htlist.cpp:102
Definition: htlist.h:35
bool IsEmpty()
Definition: htlist.h:63
#define i
Definition: md1redef.h:12
void Append(HTList *)
Definition: htlist.cpp:51
void Prepend(HTList *)
Definition: htlist.cpp:58
return NULL
Definition: cabcode.cpp:461
void RemoveAll()
Definition: htlist.cpp:76