clean format with gofmt -w
parent
823691feaa
commit
9da955ca75
|
@ -280,7 +280,6 @@ func (s *Store) internalGet(key string) *Response {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Get all the items under key
|
||||
// If key is a file return the file
|
||||
// If key is a directory reuturn an array of files
|
||||
|
@ -352,7 +351,6 @@ func (s *Store) Delete(key string, index uint64) ([]byte, error) {
|
|||
|
||||
s.Tree.delete(key)
|
||||
|
||||
|
||||
} else {
|
||||
resp.Expiration = &node.ExpireTime
|
||||
// Kill the expire go routine
|
||||
|
|
|
@ -2,9 +2,9 @@ package store
|
|||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
"sort"
|
||||
)
|
||||
"strings"
|
||||
)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
|
@ -26,7 +26,7 @@ type treeNode struct {
|
|||
}
|
||||
|
||||
// TreeNode with its key. We use it when we need to sort the treeNodes.
|
||||
type tnWithKey struct{
|
||||
type tnWithKey struct {
|
||||
key string
|
||||
tn *treeNode
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func (t *tree) set(key string, value Node) bool {
|
|||
newDir := false
|
||||
|
||||
// go through all the path
|
||||
for i = 0; i < len(nodesName) - 1; i++ {
|
||||
for i = 0; i < len(nodesName)-1; i++ {
|
||||
|
||||
// if we meet a new directory, all the directory after it must be new
|
||||
if newDir {
|
||||
|
@ -115,14 +115,14 @@ func (t *tree) set(key string, value Node) bool {
|
|||
}
|
||||
|
||||
// Get the tree node of the key
|
||||
func (t *tree)internalGet(key string) (*treeNode, bool) {
|
||||
func (t *tree) internalGet(key string) (*treeNode, bool) {
|
||||
nodesName := split(key)
|
||||
|
||||
nodeMap := t.Root.NodeMap
|
||||
|
||||
var i int
|
||||
|
||||
for i = 0; i < len(nodesName) - 1; i++ {
|
||||
for i = 0; i < len(nodesName)-1; i++ {
|
||||
node, ok := nodeMap[nodesName[i]]
|
||||
if !ok || !node.Dir {
|
||||
return nil, false
|
||||
|
@ -193,7 +193,7 @@ func (t *tree) delete(key string) bool {
|
|||
|
||||
var i int
|
||||
|
||||
for i = 0; i < len(nodesName) - 1; i++ {
|
||||
for i = 0; i < len(nodesName)-1; i++ {
|
||||
node, ok := nodeMap[nodesName[i]]
|
||||
if !ok || !node.Dir {
|
||||
return false
|
||||
|
@ -202,7 +202,7 @@ func (t *tree) delete(key string) bool {
|
|||
}
|
||||
|
||||
node, ok := nodeMap[nodesName[i]]
|
||||
if ok && !node.Dir{
|
||||
if ok && !node.Dir {
|
||||
delete(nodeMap, nodesName[i])
|
||||
return true
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ func (t *tree) traverse(f func(string, *Node), sort bool) {
|
|||
func dfs(key string, t *treeNode, f func(string, *Node)) {
|
||||
|
||||
// base case
|
||||
if len(t.NodeMap) == 0{
|
||||
if len(t.NodeMap) == 0 {
|
||||
f(key, &t.InternalNode)
|
||||
|
||||
// recursion
|
||||
|
@ -239,7 +239,7 @@ func dfs(key string, t *treeNode, f func(string, *Node)) {
|
|||
// apply the func f to each internal node
|
||||
func sortDfs(key string, t *treeNode, f func(string, *Node)) {
|
||||
// base case
|
||||
if len(t.NodeMap) == 0{
|
||||
if len(t.NodeMap) == 0 {
|
||||
f(key, &t.InternalNode)
|
||||
|
||||
// recursion
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func TestStoreGet(t *testing.T) {
|
||||
|
@ -60,7 +60,6 @@ func TestStoreGet(t *testing.T) {
|
|||
t.Fatalf("Expect cannot delet /hello, but deleted! ")
|
||||
}
|
||||
|
||||
|
||||
// test list
|
||||
ts.set("/hello/fooo", CreateTestNode("barbarbar"))
|
||||
ts.set("/hello/foooo/foo", CreateTestNode("barbarbar"))
|
||||
|
@ -73,12 +72,12 @@ func TestStoreGet(t *testing.T) {
|
|||
length := len(nodes)
|
||||
|
||||
for i := 0; i < length; i++ {
|
||||
fmt.Println(keys[i] , "=", nodes[i].Value, "[", dirs[i], "]")
|
||||
fmt.Println(keys[i], "=", nodes[i].Value, "[", dirs[i], "]")
|
||||
}
|
||||
}
|
||||
|
||||
// speed test
|
||||
for i:=0; i < 100; i++ {
|
||||
for i := 0; i < 100; i++ {
|
||||
key := "/"
|
||||
depth := rand.Intn(10)
|
||||
for j := 0; j < depth; j++ {
|
||||
|
@ -100,10 +99,10 @@ func TestStoreGet(t *testing.T) {
|
|||
ts.traverse(f, true)
|
||||
}
|
||||
|
||||
func f (key string, n *Node) {
|
||||
func f(key string, n *Node) {
|
||||
fmt.Println(key, "=", n.Value)
|
||||
}
|
||||
|
||||
func CreateTestNode(value string) Node{
|
||||
return Node{value, time.Unix(0,0), nil}
|
||||
func CreateTestNode(value string) Node {
|
||||
return Node{value, time.Unix(0, 0), nil}
|
||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Typedefs
|
||||
|
@ -85,7 +86,6 @@ func checkResponse(prefix string, index uint64, resMap *map[string]Response) boo
|
|||
return false
|
||||
}
|
||||
|
||||
|
||||
// Notify the watcher a action happened
|
||||
func (w *WatcherHub) notify(resp Response) error {
|
||||
resp.Key = path.Clean(resp.Key)
|
||||
|
|
Loading…
Reference in New Issue