src: Use len instead of n for clarity
This commit is contained in:
parent
8a539420c2
commit
d9a2ff278c
|
@ -99,14 +99,14 @@ template <typename T, typename F> bool test_flags(T t, F flags) {
|
||||||
// T *dlnext, which point to previous element and next element in the
|
// T *dlnext, which point to previous element and next element in the
|
||||||
// list respectively.
|
// list respectively.
|
||||||
template <typename T> struct DList {
|
template <typename T> struct DList {
|
||||||
DList() : head(nullptr), tail(nullptr), n(0) {}
|
DList() : head(nullptr), tail(nullptr), len(0) {}
|
||||||
|
|
||||||
DList(const DList &) = delete;
|
DList(const DList &) = delete;
|
||||||
DList &operator=(const DList &) = delete;
|
DList &operator=(const DList &) = delete;
|
||||||
|
|
||||||
DList(DList &&other) : head(other.head), tail(other.tail), n(other.n) {
|
DList(DList &&other) : head(other.head), tail(other.tail), len(other.len) {
|
||||||
other.head = other.tail = nullptr;
|
other.head = other.tail = nullptr;
|
||||||
other.n = 0;
|
other.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DList &operator=(DList &&other) {
|
DList &operator=(DList &&other) {
|
||||||
|
@ -115,16 +115,16 @@ template <typename T> struct DList {
|
||||||
}
|
}
|
||||||
head = other.head;
|
head = other.head;
|
||||||
tail = other.tail;
|
tail = other.tail;
|
||||||
n = other.n;
|
len = other.len;
|
||||||
|
|
||||||
other.head = other.tail = nullptr;
|
other.head = other.tail = nullptr;
|
||||||
other.n = 0;
|
other.len = 0;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(T *t) {
|
void append(T *t) {
|
||||||
++n;
|
++len;
|
||||||
if (tail) {
|
if (tail) {
|
||||||
tail->dlnext = t;
|
tail->dlnext = t;
|
||||||
t->dlprev = tail;
|
t->dlprev = tail;
|
||||||
|
@ -135,7 +135,7 @@ template <typename T> struct DList {
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(T *t) {
|
void remove(T *t) {
|
||||||
--n;
|
--len;
|
||||||
auto p = t->dlprev;
|
auto p = t->dlprev;
|
||||||
auto n = t->dlnext;
|
auto n = t->dlnext;
|
||||||
if (p) {
|
if (p) {
|
||||||
|
@ -155,10 +155,10 @@ template <typename T> struct DList {
|
||||||
|
|
||||||
bool empty() const { return head == nullptr; }
|
bool empty() const { return head == nullptr; }
|
||||||
|
|
||||||
size_t size() const { return n; }
|
size_t size() const { return len; }
|
||||||
|
|
||||||
T *head, *tail;
|
T *head, *tail;
|
||||||
size_t n;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> void dlist_delete_all(DList<T> &dl) {
|
template <typename T> void dlist_delete_all(DList<T> &dl) {
|
||||||
|
|
Loading…
Reference in New Issue