Skip to content

Commit

Permalink
Use tiles-space coords
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Jul 8, 2024
1 parent 5183c16 commit ce6baca
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
29 changes: 17 additions & 12 deletions api/layout/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,37 @@ const (
CheckpointPath = "checkpoint"
)

// EntriesPath builds the local path at which the leaf with the given index lives in.
// EntriesPathForLogIndex() builds the local path at which the leaf with the given index lives in.
// Note that this will be an entry bundle containing up to 256 entries and thus multiple
// indices can map to the same output path.
//
// TODO(mhutchinson): revisit to consider how partial tile suffixes should be added.
func EntriesPath(seq uint64) string {
func EntriesPathForLogIndex(seq uint64) string {
seq = seq / 256
return EntriesPath(seq)
}

func EntriesPath(bundleIndex uint64) string {
frag := []string{
"tile",
"entries",
fmt.Sprintf("x%03x", (seq>>16)&0xff),
fmt.Sprintf("x%03x", (seq>>8)&0xff),
fmt.Sprintf("%03x", seq&0xff),
fmt.Sprintf("x%03x", (bundleIndex>>16)&0xff),
fmt.Sprintf("x%03x", (bundleIndex>>8)&0xff),
fmt.Sprintf("%03x", bundleIndex&0xff),
}
return filepath.Join(frag...)
}

// TilePath builds the path to the subtree tile with the given level and index.
func TilePath(level, index uint64) string {
seq := index / 256
// TilePath builds the path to the subtree tile with the given level and index in tile space.
//
// Note that NodeCoordsToTileAddress can be used to convert from node- to tile-space.
func TilePath(tileLevel, tileIndex uint64) string {
frag := []string{
"tile",
fmt.Sprintf("%d", level),
fmt.Sprintf("x%03x", (seq>>16)&0xff),
fmt.Sprintf("x%03x", (seq>>8)&0xff),
fmt.Sprintf("%03x", seq&0xff),
fmt.Sprintf("%d", tileLevel),
fmt.Sprintf("x%03x", (tileIndex>>16)&0xff),
fmt.Sprintf("x%03x", (tileIndex>>8)&0xff),
fmt.Sprintf("%03x", tileIndex&0xff),
}
return filepath.Join(frag...)
}
33 changes: 31 additions & 2 deletions api/layout/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"
)

func TestEntriesPath(t *testing.T) {
func TestEntriesPathForLogIndex(t *testing.T) {
for _, test := range []struct {
seq uint64
wantPath string
Expand All @@ -37,6 +37,35 @@ func TestEntriesPath(t *testing.T) {
seq: 0xffeeddccbb,
wantPath: "tile/entries/x0ee/x0dd/0cc",
},
} {
desc := fmt.Sprintf("seq %d", test.seq)
t.Run(desc, func(t *testing.T) {
gotPath := EntriesPathForLogIndex(test.seq)
if gotPath != test.wantPath {
t.Errorf("got file %q want %q", gotPath, test.wantPath)
}
})
}
}

func TestEntriesPath(t *testing.T) {
for _, test := range []struct {
seq uint64
wantPath string
}{
{
seq: 0,
wantPath: "tile/entries/x000/x000/000",
}, {
seq: 255,
wantPath: "tile/entries/x000/x000/0ff",
}, {
seq: 256,
wantPath: "tile/entries/x000/x001/000",
}, {
seq: 0xdccbb,
wantPath: "tile/entries/x00d/x0cc/0bb",
},
} {
desc := fmt.Sprintf("seq %d", test.seq)
t.Run(desc, func(t *testing.T) {
Expand All @@ -61,7 +90,7 @@ func TestTilePath(t *testing.T) {
}, {
level: 15,
index: 0x455667,
wantPath: "tile/15/x000/x045/056",
wantPath: "tile/15/x045/x056/067",
},
} {
desc := fmt.Sprintf("level %x index %x", test.level, test.index)
Expand Down

0 comments on commit ce6baca

Please sign in to comment.