Skip to content

Commit fcb0bb9

Browse files
committed
handle deduplication in archives correctly
1 parent 1206606 commit fcb0bb9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var cli struct {
7171

7272
Merge struct {
7373
Archives []string `arg:"" name:"inputs_then_output" help:"One or more input archives, followed by the output name last."`
74-
} `cmd:"" help:"Merge multiple archives into a single archive" hidden:""`
74+
} `cmd:"" help:"Merge multiple archives into a single archive"`
7575

7676
Convert struct {
7777
Input string `arg:"" help:"Input archive" type:"existingfile"`

pmtiles/merge.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,16 @@ func Merge(logger *log.Logger, inputs []string) error {
9797
acc := uint64(0)
9898
addressedTiles := uint64(0)
9999
tileContents := roaring64.New()
100+
maxOffsets := make([]uint64, len(headers))
100101
for idx := range mergedEntries {
101-
// TODO: this algo is broken with any deduplication of tiles
102-
// need to bookkeep on the max seen offset in each input archive
103102
mergedEntries[idx].Entry.Offset = acc
104-
acc += uint64(mergedEntries[idx].Entry.Length)
103+
104+
// skip any deduplication (backreferences)
105+
if mergedEntries[idx].InputOffset >= maxOffsets[mergedEntries[idx].InputIdx] {
106+
acc += uint64(mergedEntries[idx].Entry.Length)
107+
maxOffsets[mergedEntries[idx].InputIdx] = mergedEntries[idx].InputOffset
108+
}
109+
105110
addressedTiles += uint64(mergedEntries[idx].Entry.RunLength)
106111
tileContents.Add(mergedEntries[idx].Entry.Offset)
107112
}

0 commit comments

Comments
 (0)