Skip to content

Commit

Permalink
Prepare to do forced sorting, maybe after everything is analyzed
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Oct 30, 2022
1 parent 479484d commit ca59141
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions modules/engine/edgeconnplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,21 @@ func (e *EdgeConnectionsPlus) insert(target *Object, eb EdgeBitmap) {
backing := e.getBacking()

for backing == nil || int(backing.maxTotal.Load()) == len(backing.data) {
e.resize()
e.maintainBacking(false)
backing = e.getBacking()
}

newMax := backing.maxTotal.Add(1)
backing.data[int(newMax-1)] = newConnection
}

func (e *EdgeConnectionsPlus) resize() {
func (e *EdgeConnectionsPlus) Optimize() {
e.lock()
e.maintainBacking(true)
e.unlock()
}

func (e *EdgeConnectionsPlus) maintainBacking(keepsize bool) {
if !e.growing.CompareAndSwap(0, 1) {
panic("growing twice")
}
Expand All @@ -256,10 +262,12 @@ func (e *EdgeConnectionsPlus) resize() {
}

oldMax := int(oldBacking.maxTotal.Load())

addLength := len(oldBacking.data)
if addLength > 8192 {
addLength = 8192
var addLength int
if !keepsize {
addLength = len(oldBacking.data)
if addLength > 8192 {
addLength = 8192
}
}
newLength := len(oldBacking.data) + addLength

Expand Down

0 comments on commit ca59141

Please sign in to comment.