forked from github/server
test for emptiness of a list (it's super-simple)
This commit is contained in:
parent
b40f3d19b0
commit
1fbe46ddfe
|
@ -47,6 +47,10 @@ int ql_length(const quicklist * ql) {
|
||||||
return ql?ql->num_elements+ql_length(ql->next):0;
|
return ql?ql->num_elements+ql_length(ql->next):0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ql_empty(const quicklist * ql) {
|
||||||
|
return !ql;
|
||||||
|
}
|
||||||
|
|
||||||
void ql_push(quicklist ** qlp, void * data) {
|
void ql_push(quicklist ** qlp, void * data) {
|
||||||
quicklist * ql = 0;
|
quicklist * ql = 0;
|
||||||
while(*qlp && ((*qlp)->next || (*qlp)->num_elements==QL_MAXSIZE)) {
|
while(*qlp && ((*qlp)->next || (*qlp)->num_elements==QL_MAXSIZE)) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
||||||
typedef struct quicklist quicklist;
|
typedef struct quicklist quicklist;
|
||||||
void * ql_get(const struct quicklist * ql, int index);
|
void * ql_get(const struct quicklist * ql, int index);
|
||||||
int ql_length(const struct quicklist * ql);
|
int ql_length(const struct quicklist * ql);
|
||||||
|
int ql_empty(const struct quicklist * ql);
|
||||||
void ql_push(struct quicklist ** qlp, void * data);
|
void ql_push(struct quicklist ** qlp, void * data);
|
||||||
int ql_delete(struct quicklist ** qlp, int index);
|
int ql_delete(struct quicklist ** qlp, int index);
|
||||||
int ql_insert(struct quicklist ** qlp, int index, void * data);
|
int ql_insert(struct quicklist ** qlp, int index, void * data);
|
||||||
|
|
|
@ -19,7 +19,9 @@ static void test_insert(CuTest * tc) {
|
||||||
|
|
||||||
static void test_insert_delete_gives_null(CuTest * tc) {
|
static void test_insert_delete_gives_null(CuTest * tc) {
|
||||||
struct quicklist * ql = NULL;
|
struct quicklist * ql = NULL;
|
||||||
|
CuAssertIntEquals(tc, 1, ql_empty(ql));
|
||||||
ql_push(&ql, (void*)42);
|
ql_push(&ql, (void*)42);
|
||||||
|
CuAssertIntEquals(tc, 0, ql_empty(ql));
|
||||||
ql_delete(&ql, 0);
|
ql_delete(&ql, 0);
|
||||||
CuAssertPtrEquals(tc, 0, ql);
|
CuAssertPtrEquals(tc, 0, ql);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue