Skip to content

Commit

Permalink
change hash map key type to be channel hash sum
Browse files Browse the repository at this point in the history
  • Loading branch information
achim-k committed Nov 2, 2023
1 parent 79d9068 commit eb8491f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions go/cli/mcap/cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ type channelID struct {
channelID uint16
}

type HashSum = [md5.Size]byte

type mcapMerger struct {
schemaIDs map[schemaID]uint16
channelIDs map[channelID]uint16
schemaIDByHash map[string]uint16
channelIDByHash map[string]uint16
channelIDByHash map[HashSum]uint16
metadataHashes map[string]bool
metadataNames map[string]bool
nextChannelID uint16
Expand All @@ -84,7 +86,7 @@ func newMCAPMerger(opts mergeOpts) *mcapMerger {
schemaIDs: make(map[schemaID]uint16),
channelIDs: make(map[channelID]uint16),
schemaIDByHash: make(map[string]uint16),
channelIDByHash: make(map[string]uint16),
channelIDByHash: make(map[HashSum]uint16),
metadataHashes: make(map[string]bool),
metadataNames: make(map[string]bool),
nextChannelID: 1,
Expand Down Expand Up @@ -143,7 +145,7 @@ func (m *mcapMerger) addMetadata(w *mcap.Writer, metadata *mcap.Metadata) error
return nil
}

func getChannelHash(channel *mcap.Channel, coalesceChannels string) string {
func getChannelHash(channel *mcap.Channel, coalesceChannels string) HashSum {
hasher := md5.New()
schemaIDBytes := make([]byte, 2)
binary.LittleEndian.PutUint16(schemaIDBytes, channel.SchemaID)
Expand All @@ -163,8 +165,7 @@ func getChannelHash(channel *mcap.Channel, coalesceChannels string) string {
die("Invalid value for --coalesce-channels: %s\n", coalesceChannels)
}

hash := hasher.Sum(nil)
return hex.EncodeToString(hash)
return HashSum(hasher.Sum(nil))
}

func (m *mcapMerger) addChannel(w *mcap.Writer, inputID int, channel *mcap.Channel) (uint16, error) {
Expand Down Expand Up @@ -264,7 +265,7 @@ func (m *mcapMerger) mergeInputs(w io.Writer, inputs []namedReader) error {

// Reset struct members
m.schemaIDByHash = make(map[string]uint16)
m.channelIDByHash = make(map[string]uint16)
m.channelIDByHash = make(map[HashSum]uint16)
m.schemaIDs = make(map[schemaID]uint16)
m.channelIDs = make(map[channelID]uint16)
m.nextChannelID = 1
Expand Down

0 comments on commit eb8491f

Please sign in to comment.