-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## 分布式缓存 | ||
|
||
#### 对于给定的 key,每次都选择同一个节点 | ||
|
||
节点固定时: | ||
|
||
把 key 的每一个字符的 ASCII 码加起来,除以 10 取余数 | ||
|
||
hash('Tom') % 10 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package geecache | ||
|
||
import ( | ||
"gee/geecache/lru" | ||
"geecache/lru" | ||
"sync" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package consistenthash | ||
|
||
import "hash/crc32" | ||
|
||
type Hash func(data []byte) uint32 | ||
|
||
type Map struct { | ||
hash Hash | ||
replicas int //虚拟节点倍数 | ||
keys []int // 哈希环 | ||
hashMap map[int]string // 虚拟节点与真实节点的映射表,键是哈希值,值是真实节点的名称 | ||
} | ||
|
||
func New(replicas int, fn Hash) *Map { | ||
m := &Map{ | ||
replicas: replicas, | ||
hash: fn, | ||
hashMap: make(map[int]string), | ||
} | ||
if m.hash == nil { | ||
m.hash = crc32.ChecksumIEEE | ||
} | ||
return m | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
module gee | ||
module geecache | ||
|
||
go 1.18 | ||
|
||
replace geecache => ./geecache | ||
|
||
// require geecache v0.0.0-00010101000000-000000000000 // indirect |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ package main | |
|
||
import ( | ||
"fmt" | ||
"gee/geecache" | ||
"geecache" | ||
"log" | ||
"net/http" | ||
) | ||
|