From eb8491fe36a26cd35f247143b5a6356d0ce607b0 Mon Sep 17 00:00:00 2001 From: Hans-Joachim Krauch Date: Thu, 2 Nov 2023 15:06:46 -0300 Subject: [PATCH] change hash map key type to be channel hash sum --- go/cli/mcap/cmd/merge.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/go/cli/mcap/cmd/merge.go b/go/cli/mcap/cmd/merge.go index 61106af374..1d7e4d5268 100644 --- a/go/cli/mcap/cmd/merge.go +++ b/go/cli/mcap/cmd/merge.go @@ -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 @@ -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, @@ -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) @@ -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) { @@ -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