diff options
| author | elee <eddy@gfxlabs.io> | 2022-03-17 21:12:25 -0500 |
|---|---|---|
| committer | elee <eddy@gfxlabs.io> | 2022-03-17 21:12:25 -0500 |
| commit | 423ce57cde83433103a4a59c04421c8c33b84287 (patch) | |
| tree | c8dd6b6c474bd3c01c19e388339e955d4dd667e6 /weed/filer/arangodb/helpers.go | |
| parent | bf745bdccb3d35c661cf75c10534ece0c0d9d392 (diff) | |
| download | seaweedfs-423ce57cde83433103a4a59c04421c8c33b84287.tar.xz seaweedfs-423ce57cde83433103a4a59c04421c8c33b84287.zip | |
prefix search, bucket implemented
Diffstat (limited to 'weed/filer/arangodb/helpers.go')
| -rw-r--r-- | weed/filer/arangodb/helpers.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/weed/filer/arangodb/helpers.go b/weed/filer/arangodb/helpers.go new file mode 100644 index 000000000..cf59957a6 --- /dev/null +++ b/weed/filer/arangodb/helpers.go @@ -0,0 +1,44 @@ +package arangodb + +import ( + "crypto/md5" + "encoding/binary" + "encoding/hex" + "io" +) + +//convert a string into arango-key safe hex bytes hash +func hashString(dir string) string { + h := md5.New() + io.WriteString(h, dir) + b := h.Sum(nil) + return hex.EncodeToString(b) +} + +// convert slice of bytes into slice of uint64 +// the first uint64 indicates the length in bytes +func bytesToArray(bs []byte) []uint64 { + out := make([]uint64, 0, 2+len(bs)/8) + out = append(out, uint64(len(bs))) + for len(bs)%8 != 0 { + bs = append(bs, 0) + } + for i := 0; i < len(bs); i = i + 8 { + out = append(out, binary.BigEndian.Uint64(bs[i:])) + } + return out +} + +// convert from slice of uint64 back to bytes +// if input length is 0 or 1, will return nil +func arrayToBytes(xs []uint64) []byte { + if len(xs) < 2 { + return nil + } + first := xs[0] + out := make([]byte, len(xs)*8) // i think this can actually be len(xs)*8-8, but i dont think an extra 8 bytes hurts... + for i := 1; i < len(xs); i = i + 1 { + binary.BigEndian.PutUint64(out[((i-1)*8):], xs[i]) + } + return out[:first] +} |
