From 5cfcba1eb9bf6d54438790dcb480e6416944f62a Mon Sep 17 00:00:00 2001 From: steak-zhuo Date: Sun, 8 Jan 2023 13:39:19 +0800 Subject: [PATCH] update the doc --- docs/chapter_searching/hashing_search.md | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/docs/chapter_searching/hashing_search.md b/docs/chapter_searching/hashing_search.md index a52f72e21..1e41297e7 100644 --- a/docs/chapter_searching/hashing_search.md +++ b/docs/chapter_searching/hashing_search.md @@ -68,13 +68,23 @@ comments: true === "JavaScript" ```js title="hashing_search.js" - + /* 哈希查找(数组) */ + function hashingSearch(map, target) { + // 哈希表的 key: 目标元素,value: 索引 + // 若哈希表中无此 key ,返回 -1 + return map.has(target) ? map.get(target) : -1; + } ``` === "TypeScript" ```typescript title="hashing_search.ts" - + /* 哈希查找(数组) */ + function hashingSearch(map: Map, target: number) { + // 哈希表的 key: 目标元素,value: 索引 + // 若哈希表中无此 key ,返回 -1 + return map.has(target) ? map.get(target) : -1; + } ``` === "C" @@ -145,19 +155,29 @@ comments: true } else { return nil } - } + } ``` === "JavaScript" ```js title="hashing_search.js" - + /* 哈希查找(链表) */ + function hashingSearch1(map, target) { + // 哈希表的 key: 目标结点值,value: 结点对象 + // 若哈希表中无此 key ,返回 null + return map.has(target) ? map.get(target) : null; + } ``` === "TypeScript" ```typescript title="hashing_search.ts" - + /* 哈希查找(链表) */ + function hashingSearch1(map: Map, target: number) { + // 哈希表的 key: 目标结点值,value: 结点对象 + // 若哈希表中无此 key ,返回 null + return map.has(target) ? map.get(target) : null; + } ``` === "C"