Created
June 25, 2021 06:56
-
-
Save export-mike/4d7099c36b8f2095784dea7e142b9e3c to your computer and use it in GitHub Desktop.
rolo
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 characters
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) | |
} |
Author
export-mike
commented
Jun 25, 2021
Notice VIRTX is a value twice?
Worth noting that gists are public (I think)
Maybe worth putting in confluence somewhere instead.
(Not that this is particularly sensitive information... but gists in general maybe not great for work)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment