mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 23:56:29 +08:00
Add the hashtable based on uthash.h to docs
This commit is contained in:
parent
dbc4906582
commit
661603d467
5 changed files with 13 additions and 10 deletions
|
@ -30,12 +30,13 @@ void constant(int n) {
|
|||
}
|
||||
|
||||
/* 哈希表 */
|
||||
typedef struct hashTable {
|
||||
struct hashTable {
|
||||
int key;
|
||||
int val;
|
||||
// 借助 LetCode 上常用的哈希表
|
||||
UT_hash_handle hh;
|
||||
} hashTable;
|
||||
UT_hash_handle hh; // 基于 uthash.h 实现
|
||||
};
|
||||
|
||||
typedef struct hashTable hashTable;
|
||||
|
||||
/* 线性阶 */
|
||||
void linear(int n) {
|
||||
|
@ -56,7 +57,6 @@ void linear(int n) {
|
|||
|
||||
// 长度为 n 的哈希表占用 O(n) 空间
|
||||
hashTable *h = NULL;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
hashTable *tmp = malloc(sizeof(hashTable));
|
||||
tmp->key = i;
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
/* 哈希表 */
|
||||
struct hashTable {
|
||||
int key; // key 为 int 型
|
||||
void *val; // val 为 void * 型
|
||||
UT_hash_handle hh; // 借助 uthash 实现的哈希表
|
||||
int key;
|
||||
void *val;
|
||||
UT_hash_handle hh; // 基于 uthash.h 实现
|
||||
};
|
||||
|
||||
typedef struct hashTable hashTable;
|
||||
|
|
|
@ -26,8 +26,7 @@ int *twoSumBruteForce(int *nums, int numsSize, int target, int *returnSize) {
|
|||
struct hashTable {
|
||||
int key;
|
||||
int val;
|
||||
// 借助 LetCode 上常用的哈希表
|
||||
UT_hash_handle hh;
|
||||
UT_hash_handle hh; // 基于 uthash.h 实现
|
||||
};
|
||||
|
||||
typedef struct hashTable hashTable;
|
||||
|
|
|
@ -705,6 +705,8 @@ $$
|
|||
=== "C"
|
||||
|
||||
```c title="space_complexity.c"
|
||||
[class]{hashTable}-[func]{}
|
||||
|
||||
[class]{}-[func]{linear}
|
||||
```
|
||||
|
||||
|
|
|
@ -126,6 +126,8 @@
|
|||
=== "C"
|
||||
|
||||
```c title="leetcode_two_sum.c"
|
||||
[class]{hashTable}-[func]{}
|
||||
|
||||
[class]{}-[func]{twoSumHashTable}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue