2011-12-16 22:51:26 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2011-12-19 13:59:37 +08:00
|
|
|
"os"
|
2011-12-16 22:51:26 +08:00
|
|
|
)
|
|
|
|
|
2011-12-19 13:59:37 +08:00
|
|
|
type NeedleKey struct {
|
|
|
|
Key uint64 "file id"
|
2011-12-16 22:51:26 +08:00
|
|
|
}
|
2011-12-19 13:59:37 +08:00
|
|
|
|
2011-12-16 22:51:26 +08:00
|
|
|
func (k *NeedleKey) String() string {
|
2011-12-19 13:59:37 +08:00
|
|
|
var tmp [12]byte
|
|
|
|
for i := uint(0); i < 8; i++ {
|
|
|
|
tmp[i] = byte(k.Key >> (8 * i))
|
|
|
|
}
|
|
|
|
return string(tmp[:])
|
2011-12-16 22:51:26 +08:00
|
|
|
}
|
|
|
|
|
2011-12-19 13:59:37 +08:00
|
|
|
type NeedleValue struct {
|
|
|
|
Offset uint32 "Volume offset" //since aligned to 8 bytes, range is 4G*8=32G
|
|
|
|
Size uint32 "Size of the data portion"
|
2011-12-16 22:51:26 +08:00
|
|
|
}
|
|
|
|
|
2011-12-19 13:59:37 +08:00
|
|
|
type NeedleMap struct {
|
2011-12-20 10:34:53 +08:00
|
|
|
m map[uint64]*NeedleValue //mapping NeedleKey(Key,AlternateKey) to NeedleValue
|
2011-12-16 22:51:26 +08:00
|
|
|
}
|
2011-12-19 13:59:37 +08:00
|
|
|
|
|
|
|
func NewNeedleMap() *NeedleMap {
|
2011-12-20 10:34:53 +08:00
|
|
|
return &NeedleMap{m: make(map[uint64]*NeedleValue)}
|
2011-12-16 22:51:26 +08:00
|
|
|
}
|
2011-12-19 13:59:37 +08:00
|
|
|
func (nm *NeedleMap) load(file *os.File) {
|
2011-12-16 22:51:26 +08:00
|
|
|
}
|
2011-12-20 10:34:53 +08:00
|
|
|
func makeKey(key uint64) uint64 {
|
|
|
|
return key
|
2011-12-19 13:59:37 +08:00
|
|
|
}
|
2011-12-20 10:34:53 +08:00
|
|
|
func (nm *NeedleMap) put(key uint64, offset uint32, size uint32) {
|
|
|
|
nm.m[makeKey(key)] = &NeedleValue{Offset: offset, Size: size}
|
2011-12-19 13:59:37 +08:00
|
|
|
}
|
2011-12-20 10:34:53 +08:00
|
|
|
func (nm *NeedleMap) get(key uint64) (element *NeedleValue, ok bool) {
|
|
|
|
element, ok = nm.m[makeKey(key)]
|
2011-12-19 13:59:37 +08:00
|
|
|
return
|
2011-12-16 22:51:26 +08:00
|
|
|
}
|