www.delorie.com/gnu/docs/avl/libavl_17.html   search  
 
Buy GNU books!


GNU libavl 2.0.1

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8 Insertion and Deletion

These functions insert and delete items in tables. There is also a function for searching a table without modifying it.

The design behind the insertion functions takes into account a couple of important issues:

 
void **tbl_probe (struct tbl_table *, void *);
void *tbl_insert (struct tbl_table *, void *);
void *tbl_replace (struct tbl_table *, void *);
void *tbl_delete (struct tbl_table *, const void *);
void *tbl_find (const struct tbl_table *, const void *);
This code is included in @refalso{15

Each of these functions takes a table to manipulate as its first argument and a table item as its second argument, here called table and item, respectively. Both arguments must be non-null in all cases. All but tbl_probe() return a table item or a null pointer.

Exercises:

1. Functions tbl_insert() and tbl_replace() return NULL in two very different situations: an error or successful insertion. Why is this not necessarily a design mistake? [answer]

2. Suggest a reason for disallowing insertion of a null item. [answer]

3. Write generic implementations of tbl_insert() and tbl_replace() in terms of tbl_probe(). [answer]


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003