1 /*********************** -*- Mode: C -*- ***********************
2 * File : bintree_iterator_init.c
3 *---------------------------------------------------------------
4 * Description
5 * ===========
6 * This operation initialises an iterator. This can then be
7 * subsequently used for iterating through a tree. This will work
8 * even if the "clientnode" which defined the current iterator has been
9 * removed before the next iterator operation.
10 *
11 * iter - the iterator instance to initialise
12 * tree - the tree to associate with this iterator
13 * clientnode - the starting point for the iteration
14 *
15 *---------------------------------------------------------------
16 * Author : Graeme McKerrell
17 * Created On : Wed Jan 28 10:33:42 2004
18 * Status : TESTED
19 *---------------------------------------------------------------
20 * HISTORY
21 * 7-Dec-2004 Graeme McKerrell
22 * Renamed to the "lub_" namespace
23 * 3-Nov-2004 Graeme McKerrell
24 * Added key bounds checking code
25 * 5-May-2004 Graeme McKerrell
26 * updates following review
27 * 9-Feb-2004 Graeme McKerrell
28 * updated to use new getkey prototype
29 * 28-Jan-2004 Graeme McKerrell
30 * Initial version
31 *---------------------------------------------------------------
32 * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
33 **************************************************************** */
34 #include "private.h"
35 #include <assert.h>
36
37 #define MAGIC_NUMBER 0x12345678
38 /*--------------------------------------------------------- */
39 void
lub_bintree_iterator_init(lub_bintree_iterator_t * this,lub_bintree_t * tree,const void * clientnode)40 lub_bintree_iterator_init(lub_bintree_iterator_t * this,
41 lub_bintree_t * tree, const void *clientnode)
42 {
43 if (clientnode != NULL) {
44 this->tree = tree;
45 this->key.magic = MAGIC_NUMBER;
46 /* fill out the iterator's key */
47 this->tree->getkeyFn(clientnode, &this->key);
48 /*
49 * this assert will fire if the client tries to store more than
50 * the current storage permits
51 */
52 assert(this->key.magic == MAGIC_NUMBER);
53 }
54 }
55
56 /*--------------------------------------------------------- */
57