-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: slimtrie: generate marshaled data for a version and add tes…
…t of unmarshal old data
- Loading branch information
1 parent
223d221
commit 973a4b6
Showing
5 changed files
with
99 additions
and
0 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,54 @@ | ||
package trie | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/golang/protobuf/proto" | ||
"github.com/openacid/slim/encode" | ||
) | ||
|
||
func MakeMarshaledData(fn string, keys []string) { | ||
|
||
if len(keys) == 0 { | ||
keys = keys50k | ||
} | ||
|
||
n := len(keys) | ||
values := make([]int32, n) | ||
for i := 0; i < n; i++ { | ||
values[i] = int32(i) | ||
} | ||
|
||
st, err := NewSlimTrie(encode.I32{}, keys, values) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
b, err := proto.Marshal(st) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fn = fmt.Sprintf(fn, st.GetVersion()) | ||
f := newFile(fn) | ||
defer f.Close() | ||
|
||
_, err = f.Write(b) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func newFile(fn string) *os.File { | ||
f, err := os.OpenFile(fn, os.O_RDWR|os.O_CREATE, 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = f.Truncate(0) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return f | ||
} |
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
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,7 @@ | ||
package main | ||
|
||
import "github.com/openacid/slim/trie" | ||
|
||
func main() { | ||
trie.MakeMarshaledData("slimtrie-data-%s", nil) | ||
} |
Binary file not shown.
File renamed without changes.