/*
 *
 *	$Header: /usr/u/wjr/src/ADT/RCS/chunk.h,v 1.2 1993/07/26 22:15:42 wjr Exp $
 *
 * Copyright (c) 1990, 1991, 1992, 1993 Cornell University.  All Rights
 * Reserved.
 *
 * Copyright (c) 1991, 1992 Xerox Corporation.  All Rights Reserved.
 *
 * Use, reproduction and preparation of derivative works of this software is
 * permitted.  Any copy of this software or of any derivative work must
 * include both the above copyright notices of Cornell University and Xerox
 * Corporation and this paragraph.  This software is made available AS IS, and
 * XEROX CORPORATION DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
 * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE, AND NOTWITHSTANDING ANY OTHER PROVISION CONTAINED
 * HEREIN, ANY LIABILITY FOR DAMAGES RESULTING FROM THE SOFTWARE OR ITS USE IS
 * EXPRESSLY DISCLAIMED, WHETHER ARISING IN CONTRACT, TORT (INCLUDING
 * NEGLIGENCE) OR STRICT LIABILITY, EVEN IF XEROX CORPORATION IS ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGES.
 */
/*
 * chunk.h - header file for the chunk module
 */
#ifndef CHUNK_H
#define CHUNK_H

#if      0
/*
BEGIN DOCUMENTATION

chunk.c - Chunk manager

A lot of programs allocate and free a lot of objects of the same type.
Using the general-purpose malloc/free routines for this is inefficient,
since they must deal with arbitrary allocations. This module is intended
to provide a simple, efficient method for allocating and freeing a lot
of objects of the same type.

Exports:
  type Chunk

  constant Chunk NULLCHUNK

  Chunk chNew(unsigned size) - create a new area for allocating elements
                               of size bytes

  void *chAlloc(Chunk c) - get a new object from that chunk

  void chFree(Chunk c, void *p) - free an object

An object of type Chunk can be used to allocate objects of the size given when
the chunk was created. Alignment is guaranteed, assuming that the size given
is actually sizeof(type), where type is the type of the object being
allocated.

 chNew creates a new chunk containing objects of the given size. If this
	is not possible, it returns NULLCHUNK.

 chAlloc allocates an object from that chunk. If this is not possible, it
	returns (void *)NULL.

 chFree frees the object, which must have been allocated from the given
	chunk.

END DOCUMENTATION */
#endif   


/*
 * Types. These types are opaque. You can't see these, really...
 */
typedef struct chunkBlob {
  struct chunkBlob *next;
  void *blob;
} chunkBlob;

typedef struct {
  struct chunkBit *freelist;
  unsigned size;
  chunkBlob *blobs;
  unsigned quantum;                          /* set to zero if chunk is deleted */
} *Chunk;

struct chunkBit {
  struct chunkBit *next;
};

typedef enum { chNoCheck, chFastCheck, chFullCheck, chReport } chCheckType;

/*
 * Constants
 */
#define	NULLCHUNK	((Chunk)NULL)

/*
 * Functions
 */
extern Chunk chNew(unsigned size);
extern Chunk chNewQ(unsigned size, unsigned quantum);
extern void *chAlloc(Chunk c);
extern void chFree(Chunk c, void *p);
extern void chDelete(Chunk c, chCheckType check);
                     
#endif
