Update hashing_search.md

补充js和ts对应的哈希查找
This commit is contained in:
zhuoqinyue 2022-12-27 14:41:29 +08:00 committed by GitHub
parent 36507b84a0
commit ca88928386
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 hashingSearch1(map: Map<number, number>, target: number) {
// 哈希表的 key: 目标元素value: 索引
// 若哈希表中无此 key ,返回 -1
return map.has(target) ? map.get(target) : -1;
}
```
=== "C"
@ -151,13 +161,22 @@ comments: true
=== "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<number, any>, target: number) {
// 哈希表的 key: 目标结点值value: 结点对象
// 若哈希表中无此 key ,返回 null
return map.has(target) ? map.get(target) : null;
}
```
=== "C"