algo/c-cpp/05_array/Array_gp.h

48 lines
1.2 KiB
C
Raw Normal View History

#ifndef __ARRAY_H__
#define __ARRAY_H__
#include <stdio.h>
#include <stdlib.h>
typedef struct Array
{
// pָ<70><D6B8><EFBFBD>Ŀռ<C4BF><D5BC><EFBFBD>С
size_t size;
// pָ<70><D6B8><EFBFBD>Ѿ<EFBFBD>ʹ<EFBFBD>õĿռ<C4BF><D5BC><EFBFBD>С
size_t len;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵Ĵ<CDB5>С
size_t typeSize;
// ֵ<><D6B5><EFBFBD>ƺ<EFBFBD><C6BA><EFBFBD>
void(*dup)(void *ptr, void *key);
// ֵ<>ͷź<CDB7><C5BA><EFBFBD>
void(*free)(void *ptr);
// ֵ<>ȽϺ<C8BD><CFBA><EFBFBD>
int(*match)(void *ptr, void *key);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
void *p;
}Array;
#define arraySetDupMethod(a, m) ((a)->dup = (m))
#define arraySetFreeMethod(a, m) ((a)->free = (m))
#define arraySetMatchMethod(a, m) ((a)->match = (m))
#define arrayGetDupMethod(a) ((a)->dup)
#define arrayGetFree(a) ((a)->free)
#define arrayGetMatchMethod(a) ((a)->match)
Array* arrayCreate();
void arrayInit(Array *array, int size, int typeSize);
int arrayInsert(Array *array, size_t pos, void *const value);
size_t arraySearchValue(Array *array, void* const value);
void* arrayIndex(Array *array, size_t index);
int arrayModify(Array *array, size_t pos, void *const value);
size_t arrayLen(Array *array);
size_t arraySize(Array *array);
void arrayEmpty(Array *array);
void arrayDelValue(Array *array, void *value);
void arrayDelIndex(Array *array, size_t pos);
#endif // !__ARRAY_H__