From 584cbbe79c7311d780e0539c5c259ea1e0a2adb7 Mon Sep 17 00:00:00 2001 From: nyym <1377514425@qq.com> Date: Mon, 26 Jun 2023 12:10:08 +0800 Subject: [PATCH] work --- APP_Framework/Applications/app_test/Kconfig | 10 ++ APP_Framework/Applications/app_test/Makefile | 11 ++ .../app_test/test_hash/test_hash.c | 12 ++ .../app_test/test_radix_tree/README.md | 15 ++ .../test_radix_tree/test_radix_tree.c | 143 ++++++++++++++++++ kfrontends/kconfig-frontends | 1 + 6 files changed, 192 insertions(+) create mode 100644 APP_Framework/Applications/app_test/test_hash/test_hash.c create mode 100644 APP_Framework/Applications/app_test/test_radix_tree/README.md create mode 100644 APP_Framework/Applications/app_test/test_radix_tree/test_radix_tree.c create mode 160000 kfrontends/kconfig-frontends diff --git a/APP_Framework/Applications/app_test/Kconfig b/APP_Framework/Applications/app_test/Kconfig index 45df5f5d5..d0eeb6ba9 100644 --- a/APP_Framework/Applications/app_test/Kconfig +++ b/APP_Framework/Applications/app_test/Kconfig @@ -239,6 +239,16 @@ menu "test app" menuconfig USER_TEST_TIMER bool "Config test soft timer" default n + + + menuconfig USER_TEST_HASH + bool "Config test hash" + default n + + + menuconfig USER_TEST_RADIX_TREE + bool "Config test radix tree" + default n endif endmenu diff --git a/APP_Framework/Applications/app_test/Makefile b/APP_Framework/Applications/app_test/Makefile index 1cf919846..7bb39a8d6 100644 --- a/APP_Framework/Applications/app_test/Makefile +++ b/APP_Framework/Applications/app_test/Makefile @@ -101,5 +101,16 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y) SRC_FILES += test_timer.c endif + + ifeq ($(CONFIG_USER_TEST_HASH),y) + SRC_FILES += test_hash/test_hash.c + endif + + + ifeq ($(CONFIG_USER_TEST_RADIX_TREE),y) + SRC_FILES += test_radix_tree/test_radix_tree.c + endif + + include $(KERNEL_ROOT)/compiler.mk endif 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..340890c94 --- /dev/null +++ b/APP_Framework/Applications/app_test/test_hash/test_hash.c @@ -0,0 +1,12 @@ +#include +#include +#include +#ifdef ADD_XIZI_FETURES + +void TestHash(void) +{ + printf("Hello World!\n"); + return; +} +PRIV_SHELL_CMD_FUNCTION(TestHash, a test sample, PRIV_SHELL_CMD_MAIN_ATTR); +#endif \ No newline at end of file diff --git a/APP_Framework/Applications/app_test/test_radix_tree/README.md b/APP_Framework/Applications/app_test/test_radix_tree/README.md new file mode 100644 index 000000000..e1cc5d8a0 --- /dev/null +++ b/APP_Framework/Applications/app_test/test_radix_tree/README.md @@ -0,0 +1,15 @@ +# ##热身赛一级赛题3:基于k210-emulator实现基数树并测试验证## + +## 1. + + + +## 2. 数据结构设计说明 + + + +## 3. 测试程序说明 + + + +## 4. 运行结果(##需结合运行测试截图按步骤说明##) \ No newline at end of file diff --git a/APP_Framework/Applications/app_test/test_radix_tree/test_radix_tree.c b/APP_Framework/Applications/app_test/test_radix_tree/test_radix_tree.c new file mode 100644 index 000000000..5851c8414 --- /dev/null +++ b/APP_Framework/Applications/app_test/test_radix_tree/test_radix_tree.c @@ -0,0 +1,143 @@ +/* +* Copyright (c) 2020 AIIT Ubiquitous Team +* 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 name: test_radix_tree.c + Description: Implementing a radix tree and a programme for testing it + History: + 1. Date: 2023/6/26 + Author: ROGEEK TEAM +*************************************************/ + + + + + + +#include +#include +#include +#include +#include +#ifdef ADD_XIZI_FETURES + + +#define ALPHABET_SIZE 26 + + +#include +#include +#include + +#define ALPHABET_SIZE 26 + +// 基数树节点的结构定义 +typedef struct TrieNode { + bool isEndOfWord; + struct TrieNode* children[ALPHABET_SIZE]; +} TrieNode; + +// 创建一个新的基数树节点 +TrieNode* createNode() { + TrieNode* node = (TrieNode*)malloc(sizeof(TrieNode)); + node->isEndOfWord = false; + + for (int i = 0; i < ALPHABET_SIZE; i++) { + node->children[i] = NULL; + } + + return node; +} + +// 向基数树中插入一个单词 +void insert(TrieNode* root, const char* word) { + TrieNode* currentNode = root; + + for (int i = 0; word[i] != '\0'; i++) { + int index = word[i] - 'a'; + + if (currentNode->children[index] == NULL) { + currentNode->children[index] = createNode(); + } + + currentNode = currentNode->children[index]; + } + + currentNode->isEndOfWord = true; +} + +// 在基数树中查找一个单词 +bool search(TrieNode* root, const char* word) { + TrieNode* currentNode = root; + + for (int i = 0; word[i] != '\0'; i++) { + int index = word[i] - 'a'; + + if (currentNode->children[index] == NULL) { + return false; + } + + currentNode = currentNode->children[index]; + } + + return (currentNode != NULL && currentNode->isEndOfWord); +} + +// 释放基数树的内存 +void freeTrie(TrieNode* node) { + if (node == NULL) { + return; + } + + for (int i = 0; i < ALPHABET_SIZE; i++) { + if (node->children[i] != NULL) { + freeTrie(node->children[i]); + } + } + + free(node); +} + +// 测试程序 +void TestRadixTree(void) { + // 创建根节点 + TrieNode* root = createNode(); + + // 插入单词 + insert(root, "hello"); + insert(root, "world"); + insert(root, "welcome"); + insert(root, "to"); + insert(root, "the"); + insert(root, "coding"); + insert(root, "world"); + + // 测试查找单词 + printf("Search Results:\n"); + printf("hello: %s\n", search(root, "hello") ? "Found" : "Not Found"); + printf("world: %s\n", search(root, "world") ? "Found" : "Not Found"); + printf("welcome: %s\n", search(root, "welcome") ? "Found" : "Not Found"); + printf("open: %s\n", search(root, "open") ? "Found" : "Not Found"); + printf("coding: %s\n", search(root, "coding") ? "Found" : "Not Found"); + + // 释放动态分配的内存 + freeTrie(root); + + return; +} + + +PRIV_SHELL_CMD_FUNCTION(TestRadixTree, a radix tree test sample, PRIV_SHELL_CMD_MAIN_ATTR); + +#endif diff --git a/kfrontends/kconfig-frontends b/kfrontends/kconfig-frontends new file mode 160000 index 000000000..e69af3132 --- /dev/null +++ b/kfrontends/kconfig-frontends @@ -0,0 +1 @@ +Subproject commit e69af3132f48f240a211f39fbfebaea8c920fb90