Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubernetes/utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7a63a7b75acd7d528af600108445c069320395db
Choose a base ref
..
head repository: kubernetes/utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 531fd6dea2101e8d0186f692cd8320c2cf2b17dd
Choose a head ref
Showing with 5 additions and 14 deletions.
  1. +5 −14 bidirectionalmap/map.go
19 changes: 5 additions & 14 deletions bidirectionalmap/map.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,8 @@ func NewBidirectionalMap[X genericinterfaces.Ordered, Y genericinterfaces.Ordere
}
}

// InsertRight inserts a new item into the right map.
// InsertRight inserts a new item into the right map, return true if the key-value was not already
// present in the map, false otherwise
func (bdm *BidirectionalMap[X, Y]) InsertRight(x X, y Y) bool {
if bdm.right[x] == nil {
bdm.right[x] = set.New[Y]()
@@ -51,20 +52,10 @@ func (bdm *BidirectionalMap[X, Y]) InsertRight(x X, y Y) bool {
return true
}

// InsertLeft inserts a new item into the left map.
// InsertLeft inserts a new item into the left map, return true if the key-value was not already
// present in the map, false otherwise
func (bdm *BidirectionalMap[X, Y]) InsertLeft(y Y, x X) bool {
if bdm.left[y] == nil {
bdm.left[y] = set.New[X]()
}
if bdm.left[y].Has(x) {
return false
}
if bdm.right[x] == nil {
bdm.right[x] = set.New[Y]()
}
bdm.right[x].Insert(y)
bdm.left[y].Insert(x)
return true
return bdm.InsertRight(x, y)
}

// GetRight returns a value from the right map.