home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / j2sdk / files / linux / j2sdklin.bin / jdk1.3.1 / include-old / bag.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-06  |  1.9 KB  |  67 lines

  1. /*
  2.  * @(#)bag.h    1.4 00/02/02
  3.  *
  4.  * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the proprietary information of Sun Microsystems, Inc.  
  7.  * Use is subject to license terms.
  8.  * 
  9.  */
  10.  
  11. #ifndef _JAVASOFT_BAG_H_
  12. #define _JAVASOFT_BAG_H_
  13.  
  14. /* Declare general routines for manipulating a bag data structure.
  15.  * Synchronized use is the responsibility of caller.
  16.  */
  17.  
  18. struct bag;
  19.  
  20. /* Must be used to create a bag.  itemSize is the size
  21.  * of the items stored in the bag. initialAllocation is a hint
  22.  * for the initial number of items to allocate. Returns the
  23.  * allocated bag, returns NULL if out of memory.
  24.  */
  25. struct bag *bagCreateBag(int itemSize, int initialAllocation);
  26.  
  27. /* Destroy the bag and reclaim the space it uses.
  28.  */
  29. void bagDestroyBag(struct bag *theBag);
  30.  
  31. /* Find 'key' in bag.  Assumes first entry in item is a pointer.
  32.  * Return found item pointer, NULL if not found. 
  33.  */
  34. void *bagFind(struct bag *theBag, void *key);
  35.  
  36. /* Add space for an item in the bag.
  37.  * Return allocated item pointer, NULL if no memory. 
  38.  */
  39. void *bagAdd(struct bag *theBag);
  40.  
  41. /* Delete specified item from bag. 
  42.  * Does no checks.
  43.  */
  44. void bagDelete(struct bag *theBag, void *condemned);
  45.  
  46. /* Delete all items from the bag.
  47.  */
  48. void bagDeleteAll(struct bag *theBag);
  49.  
  50. /* Return the count of items stored in the bag.
  51.  */
  52. int bagSize(struct bag *theBag);
  53.  
  54. /* Enumerate over the items in the bag, calling 'func' for 
  55.  * each item.  The function is passed the item and the user 
  56.  * supplied 'arg'.  Abort the enumeration if the function
  57.  * returns FALSE.  Return TRUE if the enumeration completed
  58.  * successfully and FALSE if it was aborted.
  59.  * Addition and deletion during enumeration is not supported.
  60.  */
  61. typedef bool_t (*bagEnumerateFunction)(void *item, void *arg);
  62.  
  63. bool_t bagEnumerateOver(struct bag *theBag, 
  64.                         bagEnumerateFunction func, void *arg);
  65.  
  66. #endif /* !_JAVASOFT_BAG_H_ */
  67.