Skip to content

Commit

Permalink
Experiment with Gonk
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Nov 2, 2022
1 parent 21a8cb7 commit d99d4e6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ require (
github.com/jfcg/sixb v1.3.5 // indirect
github.com/jfcg/sorty/v2 v2.0.8 // indirect
github.com/k-sone/ipmigo v0.0.0-20190922011749-b22c7a70e949 // indirect
github.com/lkarlslund/gonk v0.0.0-20221102145256-2b4b4974a471 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/open-networks/go-msgraph v0.3.1 // indirect
github.com/open2b/scriggo v0.56.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ github.com/lkarlslund/binstruct v1.3.1-0.20220418073417-7618823b3136 h1:+Kk6n+RA
github.com/lkarlslund/binstruct v1.3.1-0.20220418073417-7618823b3136/go.mod h1:md9fQkOXb+vqf3U+SVAsNfzLvKFK1Q+MJLj2v2sBj+4=
github.com/lkarlslund/go-win64api v0.0.0-20211005130710-d4f2d07ed091 h1:6y0mbZnTDDZ8pOl3C/8W8j0a6OGuxNWxU07iZeBRpYg=
github.com/lkarlslund/go-win64api v0.0.0-20211005130710-d4f2d07ed091/go.mod h1:JFCoCajhTrJw5YFNm/Xm0o+lt5jhY974icELnvnVFdc=
github.com/lkarlslund/gonk v0.0.0-20221102145256-2b4b4974a471 h1:G9NVrY4Rm1p4Jbsina4hImNACxeYYJ4iE2jGEUKT3K0=
github.com/lkarlslund/gonk v0.0.0-20221102145256-2b4b4974a471/go.mod h1:UDXqvYw0IMD1tS9gAdVJwgavVjKZqOpMJx1YOpB8L7A=
github.com/lkarlslund/ldap/v3 v3.4.4-1 h1:dcVlqedaugh0UtxgvgHMn83g4ARrmCupHvJiJ7SQb4c=
github.com/lkarlslund/ldap/v3 v3.4.4-1/go.mod h1:0wE7xreiGneIlOw9d76AykHNfq/8lNpV8ZO0A/2xnmc=
github.com/lkarlslund/stringdedup v0.6.2 h1:IcoGuXAuZxjntVnxTi7/C+RFh+gVc5wCyt4gkHp9FxA=
Expand Down
4 changes: 2 additions & 2 deletions modules/engine/attributevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func CompareAttributeValues(a, b AttributeValue) bool {
}

type AttributeAndValues struct {
AttributeValues
Attribute
values AttributeValues
attribute Attribute
}

// AttributeValues can contain one or more values
Expand Down
54 changes: 39 additions & 15 deletions modules/engine/attributevaluemap.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
package engine

import (
gsync "github.com/SaveTheRbtz/generic-sync-map-go"
"github.com/lkarlslund/gonk"
)

type AttributeValueMap struct {
// m *xsync.MapOf[Attribute, AttributeValues]
// m map[Attribute]AttributeValues
// m *haxmap.Map[Attribute, AttributeValues]
m gsync.MapOf[Attribute, AttributeValues]
// m gsync.MapOf[Attribute, AttributeValues]
m gonk.Gonk[AttributeValuesEvaluator]
}

type AttributeValuesEvaluator struct {
a Attribute
v AttributeValues
}

func (ave AttributeValuesEvaluator) Equal(ave2 AttributeValuesEvaluator) bool {
return ave.a == ave2.a
}

func (ave AttributeValuesEvaluator) LessThan(ave2 AttributeValuesEvaluator) bool {
return ave.a < ave2.a
}

func (avm *AttributeValueMap) init(preloadAttributes int) {
Expand All @@ -25,37 +39,47 @@ func (avm *AttributeValueMap) Get(a Attribute) (av AttributeValues, found bool)
// found = false // workaround until haxmap performance for deletes is fixed
// }
// av, found = avm.m[a]
av, found = avm.m.Load(a)
return
// av, found = avm.m.Load(a)
// return

ave, found := avm.m.Load(AttributeValuesEvaluator{a: a})
return ave.v, found
}

func (avm *AttributeValueMap) Set(a Attribute, av AttributeValues) {
// avm.m.Set(a, av)
// avm.m[a] = av
avm.m.Store(a, av)
// avm.m.Store(a, av)

avm.m.Store(AttributeValuesEvaluator{a: a, v: av})
}

func (avm *AttributeValueMap) Len() int {
var count int
avm.m.Range(func(u Attribute, av AttributeValues) bool {
// if av.Len() > 0 {
count++
// }
return true
})
return count
// var count int
// avm.m.Range(func(u Attribute, av AttributeValues) bool {
// // if av.Len() > 0 {
// count++
// // }
// return true
// })
// return count
return avm.m.Len()
// return len(avm.m)
// return avm.m.Size()
}

func (avm *AttributeValueMap) Clear(a Attribute) {
// avm.m.Set(a, NoValues{}) // Workaround until haxmap performance
// delete(avm.m, a)
avm.m.Delete(a)
// avm.m.Delete(a)
// avm.m.Delete(AttributeValuesEvaluator{a: a})
avm.m.Delete(AttributeValuesEvaluator{a: a})
}

func (avm *AttributeValueMap) Iterate(f func(attr Attribute, values AttributeValues) bool) {
avm.m.Range(f)
avm.m.Range(func(item AttributeValuesEvaluator) bool {
return f(item.a, item.v)
})
// for a, av := range avm.m {
// if !f(a, av) {
// break
Expand Down

0 comments on commit d99d4e6

Please sign in to comment.