




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Makefile:ROOT=.BIN=$(ROOT)/binOBJ=$(ROOT)/objSRC=$(ROOT)/srcCC=g+LVL=-gFLGS=-WallINCS=-I$(OBJ)LIBS=-L$(BIN)CMD=$(CC) $(LVL) $(FLGS) $(INCS) $(LIBS)all: mkdir ccmylib libclsecho all success%.o:$(CMD) -c $(SRC)/$*.c -o $(OBJ)/$libcls:ar -rc libcls.a $(OBJ)/*.ocp libcls.a ./test/lib/ccmylib:$(CC) -c $(LVL) $(FLGS) $(SRC)/cls_weights.c -o $(OBJ)/cls_weights.omkdir:#mkdir -p $(BIN)mkdir -p $(OBJ)clean:#rm -rf $(BIN)rm -rf $(OBJ)rm -rf libcls.a.h:#ifndef _CLSHASH_H#define _CLSHASH_H#include #include #include #include #include #include #include #include /*数据节点2*/typedef struct data_listchar *data;int data_len;int num;struct data_list *prev;struct data_list *next;hash_data_t;/*数据节点1*/typedef struct hash_listchar *key;int key_len;int count;hash_data_t *d_item;struct hash_list *prev;struct hash_list *next;hash_list_t;/*hash表*/typedef struct hash_tablehash_list_t *item;int pail_size;hash_tables_t;unsigned long hashcode(char *key, int len);int init_hash(hash_tables_t *hash_t, int size);int insert_hash(hash_tables_t *hash_t, char *key, int key_len, char *data, int data_len, int num);int find_hash(hash_tables_t *hash_t, char *key, int key_len, hash_data_t *hash_data);void free_list_node(hash_list_t *temp);int close_hash(hash_tables_t *hash_t);#endif.c:#include clshash.hunsigned long hashcode(char *key, int len)int i = 0;unsigned long hash_code = 0;while(*key) != 0 & i len)i+;hash_code = (hash_code =size)return -1;(*hash_t) = (hash_tables_t *)malloc(sizeof(hash_tables_t);if(NULL = (*hash_t)fprintf(stderr, *hash_t malloc failn);return -1;memset(*hash_t, 0x00, sizeof(*hash_t);(*hash_t)-pail_size = size;(*hash_t)-item = (hash_list_t *)malloc(sizeof(hash_list_t)*size);if (NULL = (*hash_t)-item)free(*hash_t); fprintf(stderr, (*hash_t)-item malloc failn); return -1; memset(*hash_t)-item, 0x00, sizeof(hash_tables_t)*size);int i = 0;hash_list_t *hash_l = NULL;for(i=0; iitem+i;memset(hash_l, 0x00, sizeof(hash_list_t);hash_l-key = NULL;hash_l-key_len = 0;hash_l-count = 0;hash_l-d_item = (hash_data_t *)malloc(sizeof(hash_data_t);memset(hash_l-d_item, 0x00, sizeof(hash_data_t);hash_l-d_item-data = NULL;hash_l-d_item-data_len = 0;hash_l-d_item-num = 0;hash_l-d_item-prev = NULL;hash_l-d_item-next = NULL;hash_l-prev = NULL;hash_l-next = NULL;return 0;int insert_hash(hash_tables_t *hash_t, char *key, int key_len, char *data, int data_len, int num)if(NULL=hash_t | NULL=key | 0=key_len)return -1;int is_find = 0;unsigned long hash_key = hashcode(key, key_len);unsigned long i = hash_key % (hash_t-pail_size);/是否重复添加if(hash_list_t *)hash_t-item+i)/查找是否存在hash_list_t *list_head = (hash_list_t *)hash_t-item+i;list_head = list_head-next;while (list_head != NULL)if (NULL!=list_head-key & 0=memcmp(list_head-key, key, (int)strlen(list_head-key)is_find = 1;break;list_head = list_head-next;/当查找到数据时if(is_find)hash_data_t *data_list_head = (hash_data_t *)list_head-d_item;while(NULL != data_list_head-next)data_list_head = data_list_head-next;hash_data_t *new_data_list = (hash_data_t *)malloc(sizeof(hash_data_t);new_data_list-data = (char *)malloc(data_len * sizeof(char);strcpy(new_data_list-data, data);new_data_list-data_len = data_len;new_data_list-num = num;new_data_list-prev = NULL;new_data_list-next = NULL;new_data_list-prev = data_list_head;data_list_head-next = new_data_list;/当数据不重复添加时if(!is_find)hash_list_t *new_list;new_list = (hash_list_t *)malloc(sizeof(hash_list_t);new_list-d_item = (hash_data_t *)malloc(sizeof(hash_data_t);if (NULL = new_list)fprintf(stderr, malloc failn);return -1;new_list-key = (char *)malloc(key_len * sizeof(char);strcpy(new_list-key, key);new_list-key_len = key_len;new_list-count = 1 ;hash_data_t *new_data_list;new_data_list = (hash_data_t *)malloc(sizeof(hash_data_t);if (NULL = new_data_list)fprintf(stderr, malloc failn);return -1;new_data_list-data = (char *)malloc(data_len * sizeof(char);strcpy(new_data_list-data, data);new_data_list-data_len = data_len;new_data_list-num = num;new_list-prev = NULL;new_list-next = NULL;hash_list_t *list_head = (hash_list_t *)hash_t-item+i;new_data_list-prev = NULL;new_data_list-next = NULL;hash_data_t *data_list_head = (hash_data_t *)new_list-d_item;new_data_list-prev = data_list_head;data_list_head-next = new_data_list;while(NULL != list_head-next)list_head = list_head-next;new_list-prev = list_head;list_head-next = new_list;return is_find;int find_hash(hash_tables_t *hash_t, char *key, int key_len, hash_data_t *hash_data)if(NULL=hash_t | NULL=key | 0=key_len)return -1;int is_find = 0;unsigned long hash_key = hashcode(key, key_len);unsigned long i = hash_key % (hash_t-pail_size);hash_list_t *list_head = (hash_list_t *)hash_t-item+i;list_head = list_head-next;if(NULL = list_head)return -1;doif (list_head-key!=NULL & memcmp(list_head-key, key, (int)strlen(list_head-key)=0& key_len=list_head-key_len )is_find = 1;break;list_head = list_head-next;while(NULL != list_head);if(1=is_find & NULL!=list_head)*hash_data = list_head-d_item;if(1 = is_find)return 0;elsereturn -1;void free_list_node(hash_list_t *temp)if(NULL != temp-key)hash_data_t *hash_d = temp-d_item;hash_d = hash_d-next;while(NULL != hash_d)free(hash_d-data);hash_d-data = NULL;hash_d = hash_d-next;free(hash_d);hash_d = NULL;free(temp-key);temp-key = NULL;if(NULL != temp)free(temp);temp = NULL;int close_hash(hash_tables_t *hash_t)if(NULL=hash_t & NULL=hash_t-item)return 0;int i = 0;for(i=0; ipail_size; i+)hash_list_t *pel = (hash_list_t *)hash_t-
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 地铁员工考试题及答案
- 团队项目进度管理及任务分配模板
- 助人为乐的阿姨500字10篇
- 销售团队客户信息管理工具表
- 农村环保型养殖模式应用合同
- 学习中的挫折与成长事件作文11篇
- 班级才艺展示活动话题的作文13篇
- 《信息检索与利用技巧:大学信息技术教学教案》
- 特种文献检索课件模板
- 知识管理与知识共享平台模板
- 急诊急救流程大全
- 山西血液净化护理知识竞赛考试题库(含答案)
- 2024年提前解除终止服务合同协议书
- 八年级体育田径–立定跳远教案
- 外研社版小学英语(三起)五年级上册单词默写表
- GB/T 44140-2024塔式太阳能光热发电站定日镜技术要求
- 个人资金转账合同模板
- 心理社交功能评估表
- 《征兵入伍应征公民体格检查标准条文释义》
- 电梯维护保养规则(TSG T5002-2017)
- 成都市企事业科协组织建设工作指南
评论
0/150
提交评论