Created
June 25, 2021 06:56
-
-
Save export-mike/4d7099c36b8f2095784dea7e142b9e3c to your computer and use it in GitHub Desktop.
Revisions
-
export-mike created this gist
Jun 25, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,87 @@ package main import ( // "bytes" "fmt" ) func main() { type Mapping struct { symbol string exchange string } currentMappings := []Mapping{ { symbol: "NOVN", exchange: "EBS", }, { symbol: "NOVN", exchange: "EBS", }, { symbol: "NOVN", exchange: "VIRTX", }, { symbol: "NOVNz", exchange: "VIRTX", }, } fmt.Println("current ", currentMappings) stringKeyMapping := make(map[string]string) for _, mapping := range currentMappings { stringKeyMapping[mapping.symbol] = mapping.exchange } structKeyMapping := make(map[Mapping]Mapping) for _, mapping := range currentMappings { structKeyMapping[mapping] = mapping } incomingMappings := []Mapping{ { symbol: "NOVN", exchange: "EBS", }, { symbol: "NOVN", exchange: "EBS", }, { symbol: "NOVN", exchange: "VIRTX", }, { symbol: "NOVNz", exchange: "VIRTX", }, { symbol: "NVS", exchange: "NYSE", }, } fmt.Println("incoming", incomingMappings) var deduplicated []Mapping for _, mapping := range incomingMappings { val, ok := stringKeyMapping[mapping.symbol] if ok && val == mapping.exchange { continue } fmt.Println(fmt.Sprintf("val (%v), ok(%v) := stringKeyMapping[%v]; ok && val == %v", val, ok, mapping.symbol, mapping.exchange)) deduplicated = append(deduplicated, mapping) } fmt.Println("string key method deduplicated", deduplicated) fmt.Println("struct key map", structKeyMapping) var structKeyDeduplicated []Mapping for _, mapping := range incomingMappings { if _, ok := structKeyMapping[mapping]; ok { continue } structKeyDeduplicated = append(structKeyDeduplicated, mapping) } fmt.Println("struct key method deduplicated", structKeyDeduplicated) }