Skip to content

Commit

Permalink
feat: upgrade github.com/benbjohnson/immutable (#5488)
Browse files Browse the repository at this point in the history
* feat: upgrade github.com/benbjohnson/immutable

Newer versions of this package were changed to use generics, making
them incompatible with the current code. Update to the newest
version. This has the nice side effect of reducing the amount of
type assertions.

* fix: staticcheck
  • Loading branch information
mhilton authored Jun 5, 2024
1 parent 32f7947 commit 165b17e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/SAP/go-hdb v0.14.1
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/apache/arrow/go/v7 v7.0.1
github.com/benbjohnson/immutable v0.3.0
github.com/benbjohnson/immutable v0.4.3
github.com/bonitoo-io/go-sql-bigquery v0.3.4-1.4.0
github.com/c-bata/go-prompt v0.2.2
github.com/cespare/xxhash/v2 v2.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.10.0 h1:1jh8J+JjYRp+QWKOsaZt7rGUgoyr
github.com/aws/aws-sdk-go-v2/service/sts v1.10.0/go.mod h1:jLKCFqS+1T4i7HDqCP9GM4Uk75YW1cS0o82LdxpMyOE=
github.com/aws/smithy-go v1.9.0 h1:c7FUdEqrQA1/UVKKCNDFQPNKGp4FQg3YW4Ck5SLTG58=
github.com/aws/smithy-go v1.9.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/benbjohnson/immutable v0.3.0 h1:TVRhuZx2wG9SZ0LRdqlbs9S5BZ6Y24hJEHTCgWHZEIw=
github.com/benbjohnson/immutable v0.3.0/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI=
github.com/benbjohnson/immutable v0.4.3 h1:GYHcksoJ9K6HyAUpGxwZURrbTkXA0Dh4otXGqbhdrjA=
github.com/benbjohnson/immutable v0.4.3/go.mod h1:qJIKKSmdqz1tVzNtst1DZzvaqOU1onk1rc03IeM3Owk=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
42 changes: 21 additions & 21 deletions values/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ func (d emptyDict) Release() {}

type dict struct {
t semantic.MonoType
data *immutable.SortedMap
data *immutable.SortedMap[(Value), (Value)]
}

func (d dict) Get(key, def Value) Value {
if !key.IsNull() {
v, ok := d.data.Get(key)
if ok {
return v.(Value)
return v
}
}
return def
Expand All @@ -163,11 +163,11 @@ func (d dict) Remove(key Value) Dictionary {
func (d dict) Range(f func(key, value Value)) {
itr := d.data.Iterator()
for {
key, value := itr.Next()
if key == nil {
key, value, ok := itr.Next()
if !ok {
return
}
f(key.(Value), value.(Value))
f(key, value)
}
}

Expand Down Expand Up @@ -241,7 +241,7 @@ func (d dict) Equal(v Value) bool {
equal = false
return
}
equal = value.Equal(v.(Value))
equal = value.Equal(v)
})
return equal
}
Expand All @@ -266,52 +266,52 @@ type (
timeComparer struct{}
)

func (c intComparer) Compare(a, b interface{}) int {
if i, j := a.(Value).Int(), b.(Value).Int(); i < j {
func (c intComparer) Compare(a, b Value) int {
if i, j := a.Int(), b.Int(); i < j {
return -1
} else if i > j {
return 1
}
return 0
}

func (c uintComparer) Compare(a, b interface{}) int {
if i, j := a.(Value).UInt(), b.(Value).UInt(); i < j {
func (c uintComparer) Compare(a, b Value) int {
if i, j := a.UInt(), b.UInt(); i < j {
return -1
} else if i > j {
return 1
}
return 0
}

func (c floatComparer) Compare(a, b interface{}) int {
if i, j := a.(Value).Float(), b.(Value).Float(); i < j {
func (c floatComparer) Compare(a, b Value) int {
if i, j := a.Float(), b.Float(); i < j {
return -1
} else if i > j {
return 1
}
return 0
}

func (c stringComparer) Compare(a, b interface{}) int {
if i, j := a.(Value).Str(), b.(Value).Str(); i < j {
func (c stringComparer) Compare(a, b Value) int {
if i, j := a.Str(), b.Str(); i < j {
return -1
} else if i > j {
return 1
}
return 0
}

func (c timeComparer) Compare(a, b interface{}) int {
if i, j := a.(Value).Time(), b.(Value).Time(); i < j {
func (c timeComparer) Compare(a, b Value) int {
if i, j := a.Time(), b.Time(); i < j {
return -1
} else if i > j {
return 1
}
return 0
}

func dictComparer(dictType semantic.MonoType) immutable.Comparer {
func dictComparer(dictType semantic.MonoType) immutable.Comparer[(Value)] {
if dictType.Nature() != semantic.Dictionary {
panic(UnexpectedKind(dictType.Nature(), semantic.Dictionary))
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func dictComparer(dictType semantic.MonoType) immutable.Comparer {
func NewDict(dictType semantic.MonoType) Dictionary {
return dict{
t: dictType,
data: immutable.NewSortedMap(
data: immutable.NewSortedMap[(Value), (Value)](
dictComparer(dictType),
),
}
Expand All @@ -350,13 +350,13 @@ func NewDict(dictType semantic.MonoType) Dictionary {
// that create new Dictionary values.
type DictionaryBuilder struct {
t semantic.MonoType
b *immutable.SortedMapBuilder
b *immutable.SortedMapBuilder[(Value), (Value)]
}

// NewDictBuilder will create a new DictionaryBuilder for the given
// key type.
func NewDictBuilder(dictType semantic.MonoType) DictionaryBuilder {
builder := immutable.NewSortedMapBuilder(dictComparer(dictType))
builder := immutable.NewSortedMapBuilder[(Value), (Value)](dictComparer(dictType))
return DictionaryBuilder{t: dictType, b: builder}
}

Expand All @@ -374,7 +374,7 @@ func (d *DictionaryBuilder) Get(key Value) (Value, bool) {
if !ok {
return nil, false
}
return v.(Value), true
return v, true
}

// Insert will insert a new key/value pair into the Dictionary.
Expand Down

0 comments on commit 165b17e

Please sign in to comment.