// // Basic Summary: // // Include file for dynamic_array definition // // Copyright: // // Copyright 1993 Ron Burback // Copyright 1993 Objects Plus // All rights reserved // // Description: // This is an dynamic array. The array is from 0 to n. // If you store at zero, the array grows by 1 // if you store at n+1, the array grows by 1 // There are no space limitations // // // Data elemnents: // A pointer to the linked list of chunks that materilizes the array // A pointer to a cursor that points to the last used chuck, optimization // A counter that counts the number of modification, optimization // // // Methods: // // The methods are // dynamic_array(); - standard constructor // ~dynamic_array(); - standard disctructor // void * peak(natural n); - look at a location with out changing array // void * get(natural n); - get element and remove from array // void set(natural n, void * element); - put the element at location // - array grows by 1 // void replace(natural n, void * element); - replace element, no change in array size // natural length () ; - the length // Boolean empty(); - is it empty? // Boolean full(); - is it full? (No, never) // // static Boolean test(); = quality assurance test // #ifndef _OP_DYNAMICARRAY #define _OP_DYNAMICARRAY // Macro definitions: // THRESHOLD - the number of modifications that have to be done before // we try to collect unused space #define THRESHOLD (4*CHUNK_SIZE) // // Class definition: // // dynamic_array // class dynamic_array { private: linked_chunk * TheHead ; cursor * TheCursor ; natural Modifications ; protected: void shrink(); void optimize(natural n); void gut(dynamic_array * d); public: static pool ThePool ; static char * version ; dynamic_array(); ~dynamic_array(); void * peak(natural n); void * get(natural n); void set(natural n, void * element); void replace(natural n, void * element); natural length () ; Boolean empty(); Boolean full(); static Boolean test () ; void * operator new(size_t) { return ThePool.alloc(); }; void operator delete(void * p) { ThePool.free(p); }; }; #endif