Skip to content

Commit

Permalink
Switched sort and search algorithm to external generic library
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Nov 2, 2022
1 parent 7b8580f commit 21a8cb7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ require (
github.com/open-networks/go-msgraph v0.3.1 // indirect
github.com/open2b/scriggo v0.56.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/peterrk/slices v0.0.0-20220825100938-df6f4b667142 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/tools v0.2.0 // indirect
gopkg.in/gcfg.v1 v1.2.3 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ github.com/open2b/scriggo v0.56.1/go.mod h1:FJS0k7CaKq2sNlrqAGMwU4dCltYqC1c+Eak3
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/peterrk/slices v0.0.0-20220825100938-df6f4b667142 h1:8SOzwY384RK5VRDYrMTEt5jAnf4Lodud6M6d3Zq7QJA=
github.com/peterrk/slices v0.0.0-20220825100938-df6f4b667142/go.mod h1:emTQwVvDK3Bt0uFxjHKlQ+T5eo2oBYbCsYH077YMtQ8=
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pierrec/lz4 v2.2.6+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
Expand Down Expand Up @@ -554,6 +556,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f h1:Al51T6tzvuh3oiwX11vex3QgJ2XTedFPGmbEVh8cdoc=
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
26 changes: 16 additions & 10 deletions modules/engine/edgeconnplus.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package engine

import (
"sort"
"sync"
"sync/atomic"
"unsafe"

"github.com/lkarlslund/adalanche/modules/ui"
"github.com/peterrk/slices"
)

type EdgeConnectionsPlus struct {
Expand All @@ -29,9 +29,13 @@ type Connection struct {
edges EdgeBitmap
}

func init() {
// sorty.MaxGor = 1
}
var (
connectionSorter = slices.Order[Connection]{
RefLess: func(a, b *Connection) bool {
return uintptr(unsafe.Pointer(a.target)) < uintptr(unsafe.Pointer(b.target))
},
}
)

func (e *EdgeConnectionsPlus) init() {

Expand Down Expand Up @@ -66,11 +70,12 @@ func (e *EdgeConnectionsPlus) search(wantedKey *Object) *Connection {
if backing != nil {
atomic.AddUint32(&backing.lookups, 1)

uintWantedKey := uintptr(unsafe.Pointer(wantedKey))
n, found := sort.Find(int(backing.maxClean), func(i int) int {
foundKey := uintptr(unsafe.Pointer(backing.data[i].target))
return int(uintWantedKey - foundKey)
})
// uintWantedKey := uintptr(unsafe.Pointer(wantedKey))
// n, found := sort.Find(int(backing.maxClean), func(i int) int {
// foundKey := uintptr(unsafe.Pointer(backing.data[i].target))
// return int(uintWantedKey - foundKey)
// })
n, found := connectionSorter.BinarySearch(backing.data[:backing.maxClean], Connection{target: wantedKey})
if found {
return &backing.data[n]
}
Expand Down Expand Up @@ -336,7 +341,8 @@ func (e *EdgeConnectionsPlus) maintainBacking(requestedModification sizeModifier
// Sort the new items
insertedData := newData[insertStart:insertEnd]

sort.Sort(ConnectionSliceSorter(insertedData))
connectionSorter.Sort(insertedData)
// sort.Sort(ConnectionSliceSorter(insertedData))
// sorty.Sort(len(insertedData), func(i, k, r, s int) bool {
// if uintptr(unsafe.Pointer(insertedData[i].target)) < uintptr(unsafe.Pointer(insertedData[k].target)) {
// if r != s {
Expand Down
9 changes: 0 additions & 9 deletions modules/engine/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@ func (target *Object) AbsorbEx(source *Object, fast bool) {
// fmt.Println("----------------------------------------")
absorbCriticalSection.Lock()
source.edges[Out].Range(func(outgoingTarget *Object, edges EdgeBitmap) bool {
if !outgoingTarget.IsValid() {
panic("This is bad")
}
if source == outgoingTarget {
panic("Pointing at myself")
}

// fmt.Println(unsafe.Pointer(outgoingTarget))

// Load edges from target, and merge with source edges
target.edges[Out].setEdges(outgoingTarget, edges)
source.edges[Out].del(outgoingTarget)
Expand Down

0 comments on commit 21a8cb7

Please sign in to comment.