diff --git a/go.mod b/go.mod index 85a7fd4..6125fd6 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 8c8f264..af177b7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/modules/engine/attributevalue.go b/modules/engine/attributevalue.go index ef24857..e40146a 100644 --- a/modules/engine/attributevalue.go +++ b/modules/engine/attributevalue.go @@ -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 diff --git a/modules/engine/attributevaluemap.go b/modules/engine/attributevaluemap.go index f7b03a7..c3cf35c 100644 --- a/modules/engine/attributevaluemap.go +++ b/modules/engine/attributevaluemap.go @@ -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) { @@ -25,25 +39,31 @@ 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() } @@ -51,11 +71,15 @@ func (avm *AttributeValueMap) Len() int { 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