Back to index

im-sdk  12.3.91
Classes | Typedefs | Functions
tree.h File Reference
#include "hhentry.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _TreeNode
struct  _Tree

Typedefs

typedef struct _TreeNode
typedef struct _Tree Tree

Functions

TreeNode * tree_search_hangul (Tree *tree, unsigned char *hangul)
Treetree_n_new (int n)
TreeNode * tree_node_new_with_hhitem (HHItem *data)
void tree_insert (Tree *tree, TreeNode *tnode)
void tree_clear (Tree *tree)

Class Documentation

struct _TreeNode

Definition at line 8 of file tree.h.

Collaboration diagram for _TreeNode:
Class Members
HHEntry data
HHItem * data
TreeNode * left
TreeNode * right
struct _Tree

Definition at line 14 of file tree.h.

Class Members
TreeNode * root

Typedef Documentation

typedef struct _TreeNode

Definition at line 6 of file tree.h.

typedef struct _Tree Tree

Function Documentation

void tree_clear ( Tree tree)

Definition at line 116 of file tree.c.

{
  _tree_clear (tree->root);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tree_insert ( Tree tree,
TreeNode *  tnode 
)

Definition at line 193 of file tree.c.

{
  TreeNode *ptr = tree->root ;
  TreeNode *prev;
  int comp_return;

  assert (tree != NULL);
  assert (tnode != NULL);

  if (tree == NULL || tnode == NULL){
    fprintf (stderr, "wrong parameter passed\n");
    exit (-1);
  }
  if (!ptr){
    tree->root = tnode;
    return;
  }

  while (ptr){
    prev = ptr;
    comp_return = hhitem_comp (ptr->data, tnode->data);
    if (comp_return < 0)
      ptr = ptr->left;
    else if (comp_return >0)
      ptr = ptr->right;
    else {
      /* no duplication expected, just return */
      return;
    }
  }
  if (hhitem_comp (prev->data, tnode->data) < 0)
    prev->left = tnode;
  else
    prev->right = tnode;
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree* tree_n_new ( int  n)

Definition at line 23 of file tree.c.

{
  Tree *trees;
  int i;

  if (!n)
    return NULL;
  
  trees = (Tree *) calloc (n, sizeof (Tree));
  if (!trees){
    fprintf (stderr, "tree_n_new error: memory allocation error\n");
    return NULL;
  }

  for (i = 0 ; i < n; i++){
    trees[i].root = NULL;
  }

  return trees;
}

Here is the caller graph for this function:

TreeNode* tree_node_new_with_hhitem ( HHItem data)

Definition at line 262 of file tree.c.

{
  TreeNode *p_newnode =
    (TreeNode *) calloc (1, sizeof (TreeNode));
  
  p_newnode->left = NULL;
  p_newnode->right = NULL;
  
  p_newnode->data = hhitem_new ();
  hhitem_copy (p_newnode->data, data);

  return p_newnode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

TreeNode* tree_search_hangul ( Tree tree,
unsigned char *  hangul 
)

Definition at line 43 of file tree.c.

{
  TreeNode *ret_node = NULL;
  ret_node = _tree_search_hangul (tree->root, hangul);
  return ret_node;
}

Here is the call graph for this function:

Here is the caller graph for this function: