Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/libiberty/splay-tree.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* A splay-tree datatype. 
    2    Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
     2   Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
    33   Contributed by Mark Mitchell ([email protected]).
    44
     
    7171    (*sp->delete_value)(node->value);
    7272
    73   free ((char*) node);
     73  );
    7474}
    7575
     
    228228}
    229229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
    230249/* Allocate a new splay tree, using COMPARE_FN to compare nodes,
    231250   DELETE_KEY_FN to deallocate keys, and DELETE_VALUE_FN to deallocate
    232    values.  */
     251   values.  Use xmalloc to allocate the splay tree structure, and any
     252   nodes added.  */
    233253
    234254splay_tree
     
    238258     splay_tree_delete_value_fn delete_value_fn;
    239259{
    240   splay_tree sp = (splay_tree) xmalloc (sizeof (struct splay_tree_s));
     260  return (splay_tree_new_with_allocator
     261          (compare_fn, delete_key_fn, delete_value_fn,
     262           splay_tree_xmalloc_allocate, splay_tree_xmalloc_deallocate, 0));
     263}
     264
     265
     266/* Allocate a new splay tree, using COMPARE_FN to compare nodes,
     267   DELETE_KEY_FN to deallocate keys, and DELETE_VALUE_FN to deallocate
     268   values.  */
     269
     270splay_tree
     271splay_tree_new_with_allocator (compare_fn, delete_key_fn, delete_value_fn,
     272                               allocate_fn, deallocate_fn, allocate_data)
     273     splay_tree_compare_fn compare_fn;
     274     splay_tree_delete_key_fn delete_key_fn;
     275     splay_tree_delete_value_fn delete_value_fn;
     276     splay_tree_allocate_fn allocate_fn;
     277     splay_tree_deallocate_fn deallocate_fn;
     278     void *allocate_data;
     279{
     280  splay_tree sp = (splay_tree) (*allocate_fn) (sizeof (struct splay_tree_s),
     281                                               allocate_data);
    241282  sp->root = 0;
    242283  sp->comp = compare_fn;
    243284  sp->delete_key = delete_key_fn;
    244285  sp->delete_value = delete_value_fn;
     286
     287
     288
    245289
    246290  return sp;
     
    254298{
    255299  splay_tree_delete_helper (sp, sp->root);
    256   free ((char*) sp);
     300  );
    257301}
    258302
     
    287331      splay_tree_node node;
    288332     
    289       node = (splay_tree_node) xmalloc (sizeof (struct splay_tree_node_s));
     333      node = ((splay_tree_node)
     334              (*sp->allocate) (sizeof (struct splay_tree_node_s),
     335                               sp->allocate_data));
    290336      node->key = key;
    291337      node->value = value;
     
    331377      if (sp->delete_value)
    332378        (*sp->delete_value) (sp->root->value);
    333       free (sp->root);
     379      );
    334380
    335381      /* One of the children is now the root.  Doesn't matter much
     
    369415}
    370416
     417
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
     431
     432
     433
     434
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
    371451/* Return the immediate predecessor KEY, or NULL if there is no
    372452   predecessor.  KEY need not be present in the tree.  */
     
    403483
    404484/* Return the immediate successor KEY, or NULL if there is no
    405    predecessor.  KEY need not be present in the tree.  */
     485   cessor.  KEY need not be present in the tree.  */
    406486
    407487splay_tree_node
     
    413493  splay_tree_node node;
    414494
    415   /* If the tree is empty, there is certainly no predecessor.  */
     495  /* If the tree is empty, there is certainly no cessor.  */
    416496  if (!sp->root)
    417497    return NULL;
Note: See TracChangeset for help on using the changeset viewer.