90 headp = (
index_dlist_t *)(vector + offset + elsize*head_index);
91 elp = (
index_dlist_t *)(vector + offset + elsize*index_to_add);
92 elp->
next = index_to_add;
93 elp->
prev = index_to_add;
96 headp->
next = index_to_add;
100 elp_next->
prev = index_to_add;
110 elp = (
index_dlist_t *)(vector + offset + elsize*index_to_delete);
139 void index_list_test_cmd(
int argc,
unsigned long *argv)
149 memset(tp, 0xa,
sizeof(tp[0])*
vec_len(tp));
152 headp = &((tp + head_index)->l);
153 headp->
next = headp->
prev = head_index;
155 for (i = 0; i < 3; i++) {
158 printf(
"headp next %d prev %d\n",
160 for (j = 0; j <= 3; j++) {
161 printf (
"[%d]: next %d prev %d\n", j,
162 tp[j].l.next, tp[j].l.prev);
164 printf(
"---------------\n");
168 printf(
"After all adds:\n");
170 printf(
"headp next %d prev %d\n",
173 for (j = 0; j <= 3; j++) {
174 printf (
"[%d]: next %d prev %d\n", j,
175 tp[j].l.next, tp[j].l.prev);
177 printf(
"---------------\n");
182 printf(
"after delete 1, head index %d\n", head_index);
183 headp = &((tp + head_index)->l);
184 printf(
"headp next %d prev %d\n",
186 for (j = 0; j <= 3; j++) {
187 printf (
"[%d]: next %d prev %d\n", j,
188 tp[j].l.next, tp[j].l.prev);
190 printf(
"---------------\n");
195 printf(
"after re-add 1, head index %d\n", head_index);
196 headp = &((tp + head_index)->l);
197 printf(
"headp next %d prev %d\n",
199 for (j = 0; j <= 3; j++) {
200 printf (
"[%d]: next %d prev %d\n", j,
201 tp[j].l.next, tp[j].l.prev);
203 printf(
"---------------\n");
205 for (i = 3; i >= 0; i--) {
208 printf(
"after delete, head index %d\n", head_index);
209 if (head_index !=
EMPTY) {
210 headp = &((tp + head_index)->l);
211 printf(
"headp next %d prev %d\n",
213 for (j = 0; j <= 3; j++) {
214 printf (
"[%d]: next %d prev %d\n", j,
215 tp[j].l.next, tp[j].l.prev);
218 printf(
"empty list\n");
220 printf(
"---------------\n");
233 void index_list_test_cmd(
int argc,
unsigned long *argv)
242 for (i = 0; i < 10; i++) {
247 printf (
"after adds, buckets[0] = %u\n", buckets[0]);
249 for (j = 0; j < 10; j++) {
250 printf(
"tp[%d] next %u\n", j, tp[j].l);
254 for (i = 0; i < 10; i++) {
257 printf(
"OUCH: remelem failure at index %d\n", i);
260 printf(
"OUCH: post-remelem next not EMPTY, index %d\n", i);
264 printf (
"after deletes, buckets[0] = %x\n", buckets[0]);
266 for (i = 0; i < 10; i++) {
271 printf (
"after adds, buckets[0] = %u\n", buckets[0]);
273 for (j = 0; j < 10; j++) {
274 printf(
"tp[%d] next %u\n", j, tp[j].l);
278 for (i = 9; i >= 0; i--) {
281 printf(
"OUCH: remelem failure at index %d\n", i);
283 if ((tp[i].l.next !=
EMPTY)) {
284 printf(
"OUCH: post-remelem next not EMPTY, index %d\n", i);
288 printf (
"after deletes, buckets[0] = %x\n", buckets[0]);
290 printf(
"add evens, then odds...\n");
292 for (i = 0; i < 10; i += 2) {
296 printf (
"head = buckets[0].next = %d\n", buckets[0].next);
297 for (j = 0; j < 10; j++) {
298 printf(
"tp[%d] next %u\n", j, tp[j].l);
300 printf(
"-------------\n");
303 for (i = 1; i < 10; i += 2) {
307 printf (
"head = buckets[0].next = %d\n", buckets[0].next);
308 for (j = 0; j < 10; j++) {
309 printf(
"tp[%d] next %u\n", j, tp[j].l);
311 printf(
"-------------\n");
314 printf (
"after adds, buckets[0] = %u\n", buckets[0]);
316 for (j = 0; j < 10; j++) {
317 printf(
"tp[%d] next %u\n", j, tp[j].l);
321 for (i = 9; i >= 0; i--) {
324 printf(
"OUCH: remelem failure at index %d\n", i);
327 printf(
"OUCH: post-remelem next not EMPTY, index %d\n", i);
331 printf (
"after deletes, buckets[0] = %x\n", buckets[0]);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
sll srl srl sll sra u16x4 i
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define STRUCT_OFFSET_OF(t, f)
void index_slist_addhead(index_slist_t *headp, u8 *vector, u32 elsize, u32 offset, u32 index_to_add)
static int index_slist_remelem_inline(index_slist_t *headp, u8 *vector, u32 elsize, u32 offset, u32 index_to_delete)
#define vec_free(V)
Free vector's memory (no header).
int index_slist_remelem(index_slist_t *headp, u8 *vector, u32 elsize, u32 offset, u32 index_to_delete)
void index_dlist_addtail(u32 head_index, u8 *vector, u32 elsize, u32 offset, u32 index_to_add)
template key/value backing page structure
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void index_slist_addhead_inline(index_slist_t *headp, u8 *vector, u32 elsize, u32 offset, u32 index_to_add)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
u32 index_dlist_remelem(u32 head_index, u8 *vector, u32 elsize, u32 offset, u32 index_to_delete)