style: pool->bufferpool

This commit is contained in:
lehugueni
2025-07-25 10:42:28 +02:00
parent fc3b5ccc40
commit b4d68fdd8b
19 changed files with 68 additions and 68 deletions

View File

@@ -43,7 +43,7 @@ type Evaluator struct {
SkDebug *rlwe.SecretKey
pool *rlwe.Pool
pool *rlwe.BufferPool
}
// NewEvaluator creates a new [Evaluator].

View File

@@ -144,7 +144,7 @@ type Evaluator struct {
*ckks.Evaluator
LTEvaluator *ltcommon.Evaluator
parameters ckks.Parameters
pool *rlwe.Pool
pool *rlwe.BufferPool
}
// NewEvaluator instantiates a new [Evaluator] from a [ckks.Evaluator].

View File

@@ -11,7 +11,7 @@ import (
type Evaluator struct {
schemes.Evaluator
pool *rlwe.Pool
pool *rlwe.BufferPool
}
func NewEvaluator(eval schemes.Evaluator) *Evaluator {

View File

@@ -11,7 +11,7 @@ import (
// types in addition to ciphertexts types in the rlwe package.
type Encryptor struct {
*rlwe.Encryptor
pool *rlwe.Pool
pool *rlwe.BufferPool
}
// NewEncryptor creates a new Encryptor type. Note that only secret-key encryption is

View File

@@ -11,7 +11,7 @@ import (
// [Evaluator.ExternalProduct]).
type Evaluator struct {
rlwe.Evaluator
pool *rlwe.Pool
pool *rlwe.BufferPool
}
// NewEvaluator creates a new [Evaluator] type supporting RGSW operations in addition
@@ -153,8 +153,8 @@ func (eval Evaluator) externalProductInPlaceSinglePAndBitDecomp(ct0 *rlwe.Cipher
buffQ := poolQP.GetBuffPoly()
defer poolQP.RecycleBuffPoly(buffQ)
buffQ1 := poolQP.Pool.AtLevel(0).GetBuffPoly()
defer poolQP.Pool.AtLevel(0).RecycleBuffPoly(buffQ1)
buffQ1 := poolQP.BufferPool.AtLevel(0).GetBuffPoly()
defer poolQP.BufferPool.AtLevel(0).RecycleBuffPoly(buffQ1)
buffBitDecomp := eval.pool.GetBuffUintArray()
defer eval.pool.RecycleBuffUintArray(buffBitDecomp)
// (a, b) + (c0 * rgsw[k][0], c0 * rgsw[k][1])

View File

@@ -11,7 +11,7 @@ import (
type Decryptor struct {
params Parameters
ringQ *ring.Ring
poolQ *ring.Pool
poolQ *ring.BufferPool
sk *SecretKey
}

View File

@@ -53,7 +53,7 @@ type Encryptor struct {
xsSampler ring.Sampler
basisextender *ring.BasisExtender
uniformSampler ringqp.UniformSampler
pool *Pool
pool *BufferPool
}
// GetRLWEParameters returns the underlying [Parameters].
@@ -353,7 +353,7 @@ func (enc Encryptor) encryptZeroSk(sk *SecretKey, ct interface{}) (err error) {
if ct.Degree() == 1 {
c1 = ct.Value[1]
} else {
buffPolyQ := enc.pool.Pool.AtLevel(ct.Level()).GetBuffPoly()
buffPolyQ := enc.pool.BufferPool.AtLevel(ct.Level()).GetBuffPoly()
defer enc.pool.RecycleBuffPoly(buffPolyQ)
c1 = *buffPolyQ
}

View File

@@ -17,7 +17,7 @@ type Evaluator struct {
BasisExtender *ring.BasisExtender
Decomposer *ring.Decomposer
pool *Pool
pool *BufferPool
}
// NewEvaluator creates a new [Evaluator].

View File

@@ -13,7 +13,7 @@ import (
// as well as a memory buffer for intermediate values.
type KeyGenerator struct {
*Encryptor
pool *Pool
pool *BufferPool
}
// NewKeyGenerator creates a new KeyGenerator, from which the secret and public keys, as well as [EvaluationKey].

View File

@@ -8,13 +8,13 @@ import (
"github.com/tuneinsight/lattigo/v6/utils/structs"
)
// Pool represents a pool of different objects (plaintexts, ciphertexts, polys) that can be used to instantiate temporary buffers.
type Pool struct {
*ringqp.Pool
// BufferPool represents a pool of different objects (plaintexts, ciphertexts, polys) that can be used to instantiate temporary buffers.
type BufferPool struct {
*ringqp.BufferPool
}
// NewPool returns a new pool given a RingQP, and optionally a pool to draw the backing arrays from.
func NewPool(rqp *ringqp.Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
func NewPool(rqp *ringqp.Ring, pools ...structs.BufferPool[*[]uint64]) *BufferPool {
// If no backing pool is given, we create one here.
switch lenPool := len(pools); lenPool {
case 0:
@@ -26,7 +26,7 @@ func NewPool(rqp *ringqp.Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
ringqpPool := ringqp.NewPool(rqp, pools...)
return &Pool{ringqpPool}
return &BufferPool{ringqpPool}
}
// AtLevel returns a new pool from which objects from polynomials at the given levels can be drawn.
@@ -34,14 +34,14 @@ func NewPool(rqp *ringqp.Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
// Zero level: the objects returned are built from polynomials at level 0.
// One level: the objects returned are built from polynomials in RingQ (resp. RingP) at the given level (resp. level 0).
// Two levels: the objects returned are built from polynomials in RingQ (resp. RingP) at levels[0] (resp. levels[1]).
func (pool Pool) AtLevel(levels ...int) *Pool {
return &Pool{pool.Pool.AtLevel(levels...)}
func (pool BufferPool) AtLevel(levels ...int) *BufferPool {
return &BufferPool{pool.BufferPool.AtLevel(levels...)}
}
// GetBuffCt returns a ciphertext that can be used as a buffer for intermediate computations.
// After use, the ciphertext should be recycled with [Pool.RecycleBuffCt].
// After use, the ciphertext should be recycled with [BufferPool.RecycleBuffCt].
// The optional dimensions specify the degree and level of the ciphertext (default to 2, pool.GetLevel()).
func (pool *Pool) GetBuffCt(dimensions ...int) *Ciphertext {
func (pool *BufferPool) GetBuffCt(dimensions ...int) *Ciphertext {
degree := 2
level := pool.GetLevel()
switch nbParams := len(dimensions); nbParams {
@@ -72,7 +72,7 @@ func (pool *Pool) GetBuffCt(dimensions ...int) *Ciphertext {
// RecycleBuffCt recycles a temporary ciphertext (i.e. returns its backing uint64 arrays to the pool).
// The input ciphertext must not be used after calling this method.
func (pool *Pool) RecycleBuffCt(ct *Ciphertext) {
func (pool *BufferPool) RecycleBuffCt(ct *Ciphertext) {
for i := range ct.Value {
pool.RecycleBuffPoly(&ct.Value[i])
}
@@ -80,9 +80,9 @@ func (pool *Pool) RecycleBuffCt(ct *Ciphertext) {
}
// GetBuffPt returns a plaintext that can be used as a buffer for intermediate computations.
// After use, the plaintext should be recycled with [Pool.RecycleBuffPt].
// After use, the plaintext should be recycled with [BufferPool.RecycleBuffPt].
// The optional argument specifies the level of the returned plaintext (default to pool.GetLevel()).
func (pool *Pool) GetBuffPt(level ...int) *Plaintext {
func (pool *BufferPool) GetBuffPt(level ...int) *Plaintext {
lvl := pool.GetLevel()
switch nbParams := len(level); nbParams {
case 0:
@@ -105,13 +105,13 @@ func (pool *Pool) GetBuffPt(level ...int) *Plaintext {
// RecycleBuffPt recycles a temporary plaintext (i.e. returns its backing uint64 arrays to the pool).
// The input plaintext must not be used after calling this method.
func (pool *Pool) RecycleBuffPt(pt *Plaintext) {
func (pool *BufferPool) RecycleBuffPt(pt *Plaintext) {
pool.RecycleBuffPoly(&pt.Value)
}
// GetBuffDecompQP returns buffers of polys to be used for RNS decomposition.
// After use, the array of buffers must be recycled with [Pool.RecycleBuffDecompQP].
func (pool *Pool) GetBuffDecompQP(params Parameters, levelQ, levelP int) []ringqp.Poly {
// After use, the array of buffers must be recycled with [BufferPool.RecycleBuffDecompQP].
func (pool *BufferPool) GetBuffDecompQP(params Parameters, levelQ, levelP int) []ringqp.Poly {
size := params.BaseRNSDecompositionVectorSize(levelQ, levelP)
buffDecompQP := make([]ringqp.Poly, size)
for i := 0; i < size; i++ {
@@ -122,7 +122,7 @@ func (pool *Pool) GetBuffDecompQP(params Parameters, levelQ, levelP int) []ringq
}
// RecycleBuffDecompQP recycles a temporary array of polys used for decomposition.
func (pool *Pool) RecycleBuffDecompQP(decomp []ringqp.Poly) {
func (pool *BufferPool) RecycleBuffDecompQP(decomp []ringqp.Poly) {
for i := range decomp {
pool.RecycleBuffPolyQP(&decomp[i])
}

View File

@@ -18,8 +18,8 @@ type BasisExtender struct {
constantsPtoQ []ModUpConstants
modDownConstantsPtoQ [][]uint64
modDownConstantsQtoP [][]uint64
poolQ *Pool
poolP *Pool
poolQ *BufferPool
poolP *BufferPool
}
func genmodDownConstants(ringQ, ringP *Ring) (constants [][]uint64) {

View File

@@ -6,15 +6,15 @@ import (
"github.com/tuneinsight/lattigo/v6/utils/structs"
)
// Pool represents a pool of polys that can be used (concurrently) to instantiate temporary polynomials.
type Pool struct {
// BufferPool represents a pool of polys that can be used (concurrently) to instantiate temporary polynomials.
type BufferPool struct {
level int
bufferPool structs.BufferPool[*[]uint64]
}
// NewPool returns a new pool given a ring, and optionally a pool to draw the backing arrays from.
func NewPool(ring *Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
newPool := &Pool{level: ring.level}
func NewPool(ring *Ring, pools ...structs.BufferPool[*[]uint64]) *BufferPool {
newPool := &BufferPool{level: ring.level}
switch lenPool := len(pools); lenPool {
case 0:
newPool.bufferPool = structs.NewSyncPoolUint64(ring.N())
@@ -28,34 +28,34 @@ func NewPool(ring *Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
}
// GetLevel returns the level of the polynomials obtained from the pool.
func (p Pool) GetLevel() int {
func (p BufferPool) GetLevel() int {
return p.level
}
// AtLevel returns a new pool from which polynomials at the given level can be drawn.
func (p Pool) AtLevel(level int) *Pool {
return &Pool{level, p.bufferPool}
func (p BufferPool) AtLevel(level int) *BufferPool {
return &BufferPool{level, p.bufferPool}
}
// GetBuffUintArray returns a new []uint64 slice obtained from a pool.
// After use, the slice should be recycled using the [Pool.RecycleBuffUintArray] method.
func (p Pool) GetBuffUintArray() *[]uint64 {
// After use, the slice should be recycled using the [BufferPool.RecycleBuffUintArray] method.
func (p BufferPool) GetBuffUintArray() *[]uint64 {
return p.bufferPool.Get()
}
// RecycleBuffUintArray takes a reference to a []uint64 slice and puts it back in the pool.
func (p Pool) RecycleBuffUintArray(arr *[]uint64) {
func (p BufferPool) RecycleBuffUintArray(arr *[]uint64) {
p.bufferPool.Put(arr)
}
// GetBuffPoly returns a new [Poly], built from backing []uint64 arrays obtained from a pool.
// After use, the [Poly] should be recycled using the [Pool.RecycleBuffPoly] method.
func (p Pool) GetBuffPoly() *Poly {
// After use, the [Poly] should be recycled using the [BufferPool.RecycleBuffPoly] method.
func (p BufferPool) GetBuffPoly() *Poly {
return NewPolyFromUintPool(p.bufferPool, p.level)
}
// RecycleBuffPoly takes a reference to a [Poly] and recycles its backing []uint64 arrays
// (i.e. they are returned to a pool). The input [Poly] must not be used after calling this method.
func (p Pool) RecycleBuffPoly(pol *Poly) {
func (p BufferPool) RecycleBuffPoly(pol *Poly) {
RecyclePolyInUintPool(p.bufferPool, pol)
}

View File

@@ -78,7 +78,7 @@ type Ring struct {
RescaleConstants [][]uint64
level int
pool *Pool
pool *BufferPool
}
// ConjugateInvariantRing returns the conjugate invariant ring of the receiver ring.

View File

@@ -7,14 +7,14 @@ import (
"github.com/tuneinsight/lattigo/v6/utils/structs"
)
// Pool represents a pool of polys that can be used (concurrently) to instantiate temporary polynomials in RingQP.
type Pool struct {
*ring.Pool
PoolP *ring.Pool
// BufferPool represents a pool of polys that can be used (concurrently) to instantiate temporary polynomials in RingQP.
type BufferPool struct {
*ring.BufferPool
PoolP *ring.BufferPool
}
// NewPool returns a new pool given a RingQP, and optionally a pool to draw the backing arrays from.
func NewPool(ringqp *Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
func NewPool(ringqp *Ring, pools ...structs.BufferPool[*[]uint64]) *BufferPool {
// If no backing pool is given, we create one here.
switch lenPool := len(pools); lenPool {
case 0:
@@ -24,7 +24,7 @@ func NewPool(ringqp *Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
panic(fmt.Errorf("the method takes at most 1 argument but %d were given", lenPool))
}
var poolQ, poolP *ring.Pool
var poolQ, poolP *ring.BufferPool
if ringqp.RingQ != nil {
poolQ = ring.NewPool(ringqp.RingQ, pools...)
@@ -33,7 +33,7 @@ func NewPool(ringqp *Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
poolP = ring.NewPool(ringqp.RingP, pools...)
}
return &Pool{poolQ, poolP}
return &BufferPool{poolQ, poolP}
}
// AtLevel returns a new pool from which polynomials at the given levels can be drawn.
@@ -41,7 +41,7 @@ func NewPool(ringqp *Ring, pools ...structs.BufferPool[*[]uint64]) *Pool {
// Zero level: the polyomials are returned at level 0.
// One level: the polynomials in RingQ (resp. RingP) are returned at the given level (resp. level 0).
// Two levels: the polynomials in RingQ (resp. RingP) are returned at levels[0] (resp. levels[1]).
func (p Pool) AtLevel(levels ...int) *Pool {
func (p BufferPool) AtLevel(levels ...int) *BufferPool {
var levelQ, levelP int
switch nbParams := len(levels); nbParams {
case 0:
@@ -54,21 +54,21 @@ func (p Pool) AtLevel(levels ...int) *Pool {
panic(fmt.Errorf("atlevel takes 2 parameters at most"))
}
var poolQ, poolP *ring.Pool
if p.Pool != nil {
poolQ = p.Pool.AtLevel(levelQ)
var poolQ, poolP *ring.BufferPool
if p.BufferPool != nil {
poolQ = p.BufferPool.AtLevel(levelQ)
}
if p.PoolP != nil {
poolP = p.PoolP.AtLevel(levelP)
}
return &Pool{poolQ, poolP}
return &BufferPool{poolQ, poolP}
}
// GetBuffPolyQP returns a new [Poly], built from backing []uint64 arrays obtained from a pool.
// After use, the [Poly] should be recycled using the [Pool.RecycleBuffPolyQP] method.
func (p Pool) GetBuffPolyQP() *Poly {
// After use, the [Poly] should be recycled using the [BufferPool.RecycleBuffPolyQP] method.
func (p BufferPool) GetBuffPolyQP() *Poly {
var Q, P ring.Poly
if p.Pool != nil {
if p.BufferPool != nil {
buffQ := p.GetBuffPoly()
Q = *buffQ
}
@@ -81,8 +81,8 @@ func (p Pool) GetBuffPolyQP() *Poly {
// RecycleBuffPolyQP takes a reference to a [Poly] and recycles its backing []uint64 arrays
// (i.e. they are returned to a pool). The input [Poly] must not be used after calling this method.
func (p Pool) RecycleBuffPolyQP(poly *Poly) {
if p.Pool != nil {
func (p BufferPool) RecycleBuffPolyQP(poly *Poly) {
if p.BufferPool != nil {
p.RecycleBuffPoly(&poly.Q)
}
if p.PoolP != nil {

View File

@@ -36,8 +36,8 @@ type Encoder struct {
// between the two structures is necessary.
// The size of an object returned from the pool MaxSlots() elements.
BuffBigIntPool structs.BufferPool[*[]*big.Int]
poolQ *ring.Pool
poolT *ring.Pool
poolQ *ring.BufferPool
poolT *ring.BufferPool
paramsQP []ring.ModUpConstants
qHalf []*big.Int

View File

@@ -24,8 +24,8 @@ type Evaluator struct {
// scale-invariant multiplications (transforming the BGV evaluator into
// BFV evaluator).
ScaleInvariant bool
pool *rlwe.Pool
poolQMul *ring.Pool
pool *rlwe.BufferPool
poolQMul *ring.BufferPool
}
type evaluatorBase struct {

View File

@@ -15,7 +15,7 @@ type DomainSwitcher struct {
stdToci, ciToStd *rlwe.EvaluationKey
automorphismIndex []uint64
poolQ *ring.Pool
poolQ *ring.BufferPool
}
// NewDomainSwitcher instantiate a new [DomainSwitcher] type. It may be instantiated from parameters from either RingType.

View File

@@ -68,7 +68,7 @@ type Encoder struct {
// Pools used to recycle large objects.
BuffBigIntPool structs.BufferPool[*[]*big.Int]
BuffComplexPool structs.BufferPool[Complex]
poolQ *ring.Pool
poolQ *ring.BufferPool
}
// NewEncoder creates a new [Encoder] from the target parameters.

View File

@@ -16,7 +16,7 @@ import (
type Evaluator struct {
*Encoder
*rlwe.Evaluator
pool *rlwe.Pool
pool *rlwe.BufferPool
}
// NewEvaluator creates a new [Evaluator], that can be used to do homomorphic