Skip to content

Commit

Permalink
Require comparable interface instead of constraints.Ordered for map k…
Browse files Browse the repository at this point in the history
…eys (#29)
  • Loading branch information
MagnaboscoL committed Sep 3, 2022
1 parent ebace64 commit ef17579
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions v2/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package orderedmap

import (
"container/list"
"golang.org/x/exp/constraints"
)

type Element[K constraints.Ordered, V any] struct {
type Element[K comparable, V any] struct {
Key K
Value V

element *list.Element
}

func newElement[K constraints.Ordered, V any](e *list.Element) *Element[K, V] {
func newElement[K comparable, V any](e *list.Element) *Element[K, V] {
if e == nil {
return nil
}
Expand Down
7 changes: 3 additions & 4 deletions v2/orderedmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package orderedmap

import (
"container/list"
"golang.org/x/exp/constraints"
)

type orderedMapElement[K constraints.Ordered, V any] struct {
type orderedMapElement[K comparable, V any] struct {
key K
value V
}

type OrderedMap[K constraints.Ordered, V any] struct {
type OrderedMap[K comparable, V any] struct {
kv map[K]*list.Element
ll *list.List
}

func NewOrderedMap[K constraints.Ordered, V any]() *OrderedMap[K, V] {
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V] {
return &OrderedMap[K, V]{
kv: make(map[K]*list.Element),
ll: list.New(),
Expand Down

0 comments on commit ef17579

Please sign in to comment.