Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTList: keep minimal class #3281

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 4 additions & 50 deletions src/ivoc/htlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@

/*****************************************************************************/

HTList::HTList(void* p) {
HTList::HTList() {
_next = this;
_prev = this;
_object = p;
}

HTList::~HTList() {
HTList* next = _next;
if (next != this && next != NULL) {
Remove(this);
this->Remove();

Check warning on line 49 in src/ivoc/htlist.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/htlist.cpp#L49

Added line #L49 was not covered by tests
delete next;
}
}
Expand All @@ -59,19 +58,6 @@
_prev = e;
}

void HTList::Prepend(HTList* e) {
_next->_prev = e;
e->_prev = this;
e->_next = _next;
_next = e;
}

void HTList::Remove(HTList* e) {
e->_prev->_next = e->_next;
e->_next->_prev = e->_prev;
e->_prev = e->_next = NULL;
}

void HTList::Remove() {
if (_prev) {
_prev->_next = _next;
Expand All @@ -81,41 +67,9 @@
}
_prev = _next = NULL;
}

void HTList::RemoveAll() {
while (!IsEmpty()) {
Remove(First());
}
}
void HTList::Delete(void* p) {
HTList* e;

e = Find(p);
if (e != NULL) {
Remove(e);
delete e;
}
}

HTList* HTList::Find(void* p) {
HTList* e;

for (e = _next; e != this; e = e->_next) {
if (e->_object == p) {
return e;
}
}
return NULL;
}

HTList* HTList::operator[](int count) {
HTList* pos = First();
int i;

for (i = 1; i < count && pos != End(); ++i) {
pos = pos->Next();
}
if (i == count) {
return pos;
First()->Remove();
}
return NULL;
}
25 changes: 1 addition & 24 deletions src/ivoc/htlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,18 @@ for fast insertion, deletion, iteration

class HTList {
public:
HTList(void* = NULL);
HTList();
virtual ~HTList();

bool IsEmpty();
void Append(HTList*);
void Prepend(HTList*);
void Remove(HTList*);
void Remove();
void RemoveAll();
void Delete(void*);
HTList* Find(void*);
HTList* First();
HTList* Last();
HTList* End();
HTList* Next();
HTList* Prev();

void* vptr();
void* operator()();
HTList* operator[](int count);

protected:
void* _object;
HTList* _next;
HTList* _prev;
};
Expand All @@ -66,21 +55,9 @@ inline bool HTList::IsEmpty() {
inline HTList* HTList::First() {
return _next;
}
inline HTList* HTList::Last() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's a first there should be a last. it might not exist out of lazyness, but removing it feels excessive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the purpose of this patch was to reduce this class as most as possible, as no one will use it anymore (I hope). So when trying to replace by something else this become easier.

return _prev;
}
inline HTList* HTList::End() {
return this;
}
inline HTList* HTList::Next() {
return _next;
}
inline HTList* HTList::Prev() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the pair next prev.

return _prev;
}
inline void* HTList::operator()() {
return _object;
}
inline void* HTList::vptr() {
return _object;
}
4 changes: 2 additions & 2 deletions src/nrncvode/netcvode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5241,7 +5241,7 @@ void ConditionEvent::abandon_statistics(Cvode* cv) {
}

WatchCondition::WatchCondition(Point_process* pnt, double (*c)(Point_process*))
: HTList(nullptr) {
: HTList() {
pnt_ = pnt;
c_ = c;
watch_index_ = 0; // For transfer, will be a small positive integer.
Expand Down Expand Up @@ -5281,7 +5281,7 @@ void WatchCondition::activate(double flag) {
id = (cv->nctd_ > 1) ? thread()->id : 0;
HTList*& wl = cv->ctd_[id].watch_list_;
if (!wl) {
wl = new HTList(nullptr);
wl = new HTList();
net_cvode_instance->wl_list_[id].push_back(wl);
}
Remove();
Expand Down
Loading