From 6043fbba9e18b632697a7d88d24a02d0a56ba36d Mon Sep 17 00:00:00 2001 From: Mao1223 Date: Mon, 9 Oct 2023 14:18:13 +0800 Subject: [PATCH] ADD file via upload --- .../app_test/test_hash/test_hash.c | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 APP_Framework/Applications/app_test/test_hash/test_hash.c diff --git a/APP_Framework/Applications/app_test/test_hash/test_hash.c b/APP_Framework/Applications/app_test/test_hash/test_hash.c new file mode 100644 index 000000000..de045b7e4 --- /dev/null +++ b/APP_Framework/Applications/app_test/test_hash/test_hash.c @@ -0,0 +1,109 @@ +/* +* 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. +*/ +/** + * @brief Priv-shell Command definition + * + * @param _func Command function + * @param _desc Command description + * @param _attr Command attributes if need + */ +#include +#include +// #include +#include +// hash code beginning +#include +#include + +#define HASHSIZE 12 +#define NULLKEY -32768 +typedef struct +{ + int *elem; + int count; +}HashTable; +int m=0; + +//初始化散列表 +int InitHashTable(HashTable *H) +{ + int i; + m=HASHSIZE; + H->count=m; + H->elem=(int*)malloc(m*sizeof(int)); + for(i=0;ielem[i]=NULLKEY; + return 1; +} +//散列函数 +int Hash(int key) +{ + return key%m; +} +//插入关键字进入散列表 +void InsertHash(HashTable *H,int key) +{ + int addr=Hash(key); + while(H->elem[addr]!=NULLKEY) + addr=(addr+1)%m; + H->elem[addr]=key; +} + +//散列表查找关键字 +int SearchHash(HashTable H,int key,int *addr) +{ + *addr=Hash(key); + while(H.elem[*addr]!=key) + { + *addr=(*addr+1)%m; + if(H.elem[*addr]==NULLKEY||*addr==Hash(key)) + { + return -1; + } + } + return *addr; +} + + +extern int FrameworkInit(); +extern void ApplicationOtaTaskInit(void); +int main(void) +{ + + int a[12]={12,67,56,16,25,37,22,29,15,47,48,34}; + HashTable H; + int i; + InitHashTable(&H); + printf("The initial array is as follows:\n"); + for(i=0;i