Plan 9 from Bell Labs’s /usr/web/sources/contrib/de0u/root/sys/src/cmd/divergefs/array.h

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.



typedef struct Array
{
  uint total;
  uint capacity;
  void **elements;
} Array;


/** constructor */
Array *array_new(void);

Array *array_new_size(uint size);

/** 
 * destructor.  Frees the associated array which should only be called on arrays
 * that have been allocated by array_new.
 */
void array_free(Array *self);

void array_free_with(Array *self, functionunary free_each);

/** Remove all the items in the array */
void array_clear(Array *self);

void array_clear_with(Array *self, functionunary clear);

/** return element at index */
void *array_at(Array *self, uint index);

/** put the particular pointer at the index */
void array_put(Array *self, uint index, void *p);

/** add a new entry to the array */
void array_add(Array *self, void *p);

/** gets the number of elements in self */
uint array_size(Array *self);

/** resize the array to the new size */
void array_resize(Array *self, uint size);

/** resize with default value for newly allocated storage if any */
void array_resize_with(Array *self, uint size, generator default_value);

/** internal iteration. */
void array_do(Array *self, collectioneach each, void *arg);

void array_unary_do(Array *self, functionunary each);


/** finds the first element such that detect(item, arg) returns true */
bool array_detect(Array *self, 
  collectiondetect detect, void **result, void *arg);

void *array_last(Array *self);

void array_push(Array *self, void *p);

void *array_pop(Array *self);

bool array_isempty(Array *self);

bool array_notempty(Array *self);


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.