luet/vendor/github.com/crillab/gophersat/solver/clause_alloc.go
Ettore Di Giacinto 2f6bef14d5
Revert "update vendor/"
This reverts commit 7ce522110e.
2020-02-11 14:55:49 +01:00

30 lines
832 B
Go

package solver
// This file deals with an attempt for an efficient clause allocator/deallocator, to relax GC's work.
const (
nbLitsAlloc = 5000000 // How many literals are initialized at first?
)
type allocator struct {
lits []Lit // A list of lits, that will be sliced to make []Lit
ptrFree int // Index of the first free item in lits
}
var alloc allocator
// newLits returns a slice of lits containing the given literals.
// It is taken from the preinitialized pool if possible,
// or is created from scratch.
func (a *allocator) newLits(lits ...Lit) []Lit {
if a.ptrFree+len(lits) > len(a.lits) {
a.lits = make([]Lit, nbLitsAlloc)
copy(a.lits, lits)
a.ptrFree = len(lits)
return a.lits[:len(lits)]
}
copy(a.lits[a.ptrFree:], lits)
a.ptrFree += len(lits)
return a.lits[a.ptrFree-len(lits) : a.ptrFree]
}