** 文 件 名: data_struct.h
**
** 创 建 人: 齐鲁桐
**
** 文件创建日期: 2019 年 2 月 21 日
**
** 描 述: 一些自定义数据结构的头文件.
*********************************************************************************************************/
#ifndef __DATA_STRUCT__H__
#define __DATA_STRUCT__H__
需要引入的头文件
*********************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
宏定义
*********************************************************************************************************/
#define NEW(type) (type *)malloc(sizeof(type))
#define XFREE(x) \
free(x); \
x = NULL;
#define STRING char *
数据结构
*********************************************************************************************************/
enum _Boolean { True = 1,
False = 0 };
typedef enum _Boolean Bool;
typedef struct list {
STRING value;
struct list *last;
struct list *next;
} * List;
typedef struct hashentry {
void * key;
void * value;
struct hashentry *next;
} * HashEntry;
typedef struct hashmap *HashMap;
typedef int (*HashCode)(HashMap map, void *key);
typedef Bool (*HashEqual)(void *key1, void *key2);
typedef void (*HashPut)(HashMap map, void *key, void *value);
typedef void *(*HashGet)(HashMap map, void *key);
typedef Bool (*HashRemove)(HashMap map, void *key);
typedef void (*HashClear)(HashMap map);
typedef Bool (*HashExists)(HashMap map, void *key);
typedef struct hashmap {
HashEntry list;
int listSize;
int size;
HashCode hashCode;
HashEqual equal;
HashPut put;
HashGet get;
HashRemove remove;
HashClear clear;
HashExists exists;
} * HashMap;
typedef struct hashmapiterator {
HashMap hashMap;
HashEntry entry;
int hashCode;
int count;
} * HashMapIterator;
链表方法
*********************************************************************************************************/
List list_create();
List list_head(List list);
List list_tail(List list);
List list_index(List list, int index);
List list_append(List list, STRING str);
List list_remove(List list, STRING str);
List list_change(List list, STRING str);
void list_delete(List list);
HashMap方法
*********************************************************************************************************/
HashMap hashmap_create();
int default_HashCode(HashMap map, void *key);
void hashmap_reset(HashMap hashMap, int listSize);
void hashmap_delete(HashMap map);
void hashmap_put(HashMap map, void *key, void *value);
void hashmap_clear(HashMap map);
void *hashmap_get(HashMap map, void *key);
Bool hashmap_equal(void *key1, void *key2);
Bool hashmap_exists(HashMap map, void *key);
Bool hashmap_remove(HashMap map, void *key);
Bool hashmap_hasNext(HashMapIterator iterator);
HashMapIterator hashmap_iterator(HashMap map);
HashMapIterator hashmap_next(HashMapIterator iterator);
STRING string_copy(STRING str);
#endif
END
*********************************************************************************************************/