function lfds710_btree_au_get_by_absolute_position_and_then_by_relative_position

From liblfds.org
Jump to navigation Jump to search

Source Files

└───liblfds710
    ├───inc
    │   └───liblfds710
    │           lfds710_btree_addonly_unbalanced.h
    └───src
        └───llfds710_btree_addonly_unbalanced
                lfds710_btree_addonly_unbalanced_get.c

Opaque Structures

struct lfds710_btree_au_element;
struct lfds710_btree_au_state;

Enums

enum lfds710_btree_au_absolute_position
{
  LFDS710_BTREE_AU_ABSOLUTE_POSITION_ROOT,
  LFDS710_BTREE_AU_ABSOLUTE_POSITION_SMALLEST_IN_TREE,
  LFDS710_BTREE_AU_ABSOLUTE_POSITION_LARGEST_IN_TREE
};

enum lfds710_btree_au_relative_position
{
  LFDS710_BTREE_AU_RELATIVE_POSITION_UP,
  LFDS710_BTREE_AU_RELATIVE_POSITION_LEFT,
  LFDS710_BTREE_AU_RELATIVE_POSITION_RIGHT,
  LFDS710_BTREE_AU_RELATIVE_POSITION_SMALLEST_ELEMENT_BELOW_CURRENT_ELEMENT,
  LFDS710_BTREE_AU_RELATIVE_POSITION_LARGEST_ELEMENT_BELOW_CURRENT_ELEMENT,
  LFDS710_BTREE_AU_RELATIVE_POSITION_NEXT_SMALLER_ELEMENT_IN_ENTIRE_TREE,
  LFDS710_BTREE_AU_RELATIVE_POSITION_NEXT_LARGER_ELEMENT_IN_ENTIRE_TREE
};

Prototypes

int lfds710_btree_au_get_by_absolute_position_and_then_by_relative_position( struct lfds710_btree_au_state *baus,
                                                                             struct lfds710_btree_au_element **baue,
                                                                             enum lfds710_btree_au_absolute_position absolute_position,
                                                                             enum lfds710_btree_au_relative_position relative_position );

Parameters

struct lfds710_btree_au_state *baus

A pointer to an initialized lfds710_btree_au_state.

struct lfds710_btree_au_element **baue

If *baue is NULL, then this argument is set to point to the element indicated by position. If *baue is not NULL, then it must point to an element in a btree, and then this argument is set to the element indicated by the direction argument, using *baue* as the starting point.

enum lfds710_btree_au_absolute_position absolute_position

Indicates which location in the btree to begin iterating from. Only used when *baue is NULL.

enum lfds710_btree_au_relative_position relative_position

Indicates which direction the next iteration step should take. Only used when *baue is not NULL (and so points to an element in a tree).

Return Value

Returns 1 if an element was found, 0 if not, which occurs only on empty tree or on reaching end-of-tree (e.g. attempting to get the next largest element at the largest element).

Notes

This is a convenience function for iterating over btrees in a compact manner.

Expected use is in while() loops, to iterate over a btree, like so (here performing an in-order walk, smallest to largest);

struct lfds710_btree_au_element
  *baue = NULL;

void
  *user_data

while( lfds710_btree_au_get_by_absolute_position_and_then_by_relative_position(&baus, &baue, LFDS710_BTREE_AU_ABSOLUTE_POSITION_SMALLEST_IN_TREE, LFDS710_BTREE_AU_RELATIVE_POSITION_NEXT_LARGER_ELEMENT_IN_ENTIRE_TREE) )
{
  user_data = LFDS710_BTREE_AU_GET_VALUE_FROM_ELEMENT( *baue );

  // TRD : do work
}

See Also