forked from xuos/xiuos
delete no need
This commit is contained in:
parent
5a02b89ffc
commit
339ea93b09
|
@ -24,7 +24,7 @@ endif
|
|||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_FILES := test_shell.c
|
||||
SRC_FILES += test_hash.c
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_ADC),y)
|
||||
SRC_FILES += test_adc.c
|
||||
endif
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: test_ethernet.c
|
||||
* @brief: a application of ethernet function
|
||||
* @version: 1.1
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2022/12/17
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#include <xs_hash.h>
|
||||
|
||||
int Testhash(void)
|
||||
{
|
||||
Element a[]={{12,1},{2,2},{31,3},{45,4},{8,5},{45,5}};
|
||||
|
||||
int n = sizeof(a)/sizeof(Element);
|
||||
Hash_table *h = Creat_Table(n);
|
||||
int i = 0;
|
||||
for(i = 0 ; i<n ; i++)
|
||||
{
|
||||
Insert(h,a[i]);
|
||||
}
|
||||
print_Table(h); // 打印哈希表
|
||||
printf("%d\n\n", lookup(h,12)->data->value); //查找key值为12的Element
|
||||
printf("%d\n",h->length); //打印哈希表的元素个数
|
||||
Destroy_Table(h); // 摧毁哈希表
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(Testhash, a hash test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
|
@ -14,7 +14,7 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
|||
ifeq ($(CONFIG_RESOURCES_LWIP),y)
|
||||
SRC_DIR += socket_demo
|
||||
endif
|
||||
SRC_DIR +=mqtt_demo
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: xs_hash.h
|
||||
* @brief: hash table
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2023/7/10
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include<stdlib.h>
|
||||
#include "xs_base.h"
|
||||
|
||||
#define REMAINDER 11
|
||||
|
||||
typedef struct element
|
||||
{
|
||||
uint8_t key;
|
||||
uint8_t value;
|
||||
uint8_t hash;
|
||||
}Element;
|
||||
|
||||
|
||||
typedef struct Pnode
|
||||
{
|
||||
Element *data;
|
||||
struct Pnode *next;
|
||||
}Node;
|
||||
|
||||
|
||||
typedef struct hash_table
|
||||
{
|
||||
uint8_t size;
|
||||
uint8_t length;
|
||||
struct Pnode *head;
|
||||
}Hash_table;
|
||||
|
||||
|
||||
Hash_table* Creat_Table(int table_size)
|
||||
{
|
||||
Hash_table *h = (Hash_table *)malloc(sizeof(Hash_table));
|
||||
h->size = REMAINDER;
|
||||
h->head = (Node *)malloc((h->size)*sizeof(Node));
|
||||
h->length = 0;
|
||||
int i = 0;
|
||||
for(i=0 ; i<h->size ; i++)
|
||||
{
|
||||
h->head[i].next = NULL;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
int hash(int value)
|
||||
{
|
||||
return value%REMAINDER;
|
||||
}
|
||||
|
||||
Node *lookup(Hash_table *h , int key)
|
||||
{
|
||||
int i;
|
||||
i = hash(key);
|
||||
Node * p = h->head[i].next;
|
||||
while(p && key != p->data->key)
|
||||
{
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Insert(Hash_table *h , Element k)
|
||||
{
|
||||
Node * p = lookup(h,k.key);
|
||||
if(!p)
|
||||
{
|
||||
Node *q = (Node *)malloc(sizeof(Node));
|
||||
q->data = (Element *)malloc(sizeof(Element));
|
||||
(q->data)->key = k.key;
|
||||
(q->data)->value = k.value;
|
||||
int position;
|
||||
position = (q->data)->hash = hash(k.key);
|
||||
q->next = h->head[position].next;
|
||||
h->head[position].next = q;
|
||||
|
||||
h->length += 1;
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("The keys is exist !\n");
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
void Destroy_Table(Hash_table *h)
|
||||
{
|
||||
int i;
|
||||
Node *p , *q;
|
||||
for(i=0 ; i<h->size ; i++)
|
||||
{
|
||||
p = h->head[i].next;
|
||||
while(p)
|
||||
{
|
||||
q=p->next;
|
||||
free(p);
|
||||
p=q;
|
||||
}
|
||||
}
|
||||
free(h->head);
|
||||
free(h);
|
||||
}
|
||||
|
||||
|
||||
void print_Table(Hash_table *h)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < h->size ; i++)
|
||||
{
|
||||
Node * p = h->head[i].next;
|
||||
while (p)
|
||||
{
|
||||
printf("[%d-%d] ",p->data->key, p->data->value);
|
||||
p = p->next;
|
||||
}
|
||||
printf("NULL\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ SRC_DIR += api
|
|||
SRC_DIR += arch
|
||||
SRC_DIR += core
|
||||
SRC_DIR += netif
|
||||
SRC_DIR += include
|
||||
|
||||
|
||||
SRC_DIR += apps
|
||||
|
||||
|
@ -10,7 +10,7 @@ LWIP_DIR += api
|
|||
LWIP_DIR += arch
|
||||
LWIP_DIR += core
|
||||
LWIP_DIR += netif
|
||||
LWIP_DIR += include
|
||||
|
||||
|
||||
LWIP_DIR += apps
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
// #define LWIP_API_MSG_DEBUG
|
||||
#endif
|
||||
|
||||
// #define LWIP_SOCKETS_DEBUG 1
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#ifdef LWIP_SYS_DEBUG
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
SRC_DIR += lwip
|
||||
|
||||
LWIP_DIR += lwip
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,6 +0,0 @@
|
|||
SRC_DIR += apps
|
||||
|
||||
LWIP_DIR += apps
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
Loading…
Reference in New Issue