Skip to content

Commit

Permalink
🦄 refactor: 调整目录结构
Browse files Browse the repository at this point in the history
  • Loading branch information
p3ddd committed Apr 5, 2022
1 parent d5a8815 commit ba5ce58
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
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.
2 changes: 1 addition & 1 deletion geecache/cache.go → cache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package geecache

import (
"gee/geecache/lru"
"geecache/lru"
"sync"
)

Expand Down
24 changes: 24 additions & 0 deletions consistenthash/consistenthash.go
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.
6 changes: 1 addition & 5 deletions go.mod
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.
2 changes: 1 addition & 1 deletion main.go → main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"gee/geecache"
"geecache"
"log"
"net/http"
)
Expand Down

0 comments on commit ba5ce58

Please sign in to comment.