github.com/consensys/gnark@v0.11.0/constraint/linear_expression.go (about)

     1  // Copyright 2021 ConsenSys AG
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package constraint
    16  
    17  // A LinearExpression is a linear combination of Term
    18  type LinearExpression []Term
    19  
    20  // Clone returns a copy of the underlying slice
    21  func (l LinearExpression) Clone() LinearExpression {
    22  	res := make(LinearExpression, len(l))
    23  	copy(res, l)
    24  	return res
    25  }
    26  
    27  func (l LinearExpression) String(r Resolver) string {
    28  	sbb := NewStringBuilder(r)
    29  	sbb.WriteLinearExpression(l)
    30  	return sbb.String()
    31  }
    32  
    33  func (l LinearExpression) Compress(to *[]uint32) {
    34  	(*to) = append((*to), uint32(len(l)))
    35  	for i := 0; i < len(l); i++ {
    36  		(*to) = append((*to), l[i].CID, l[i].VID)
    37  	}
    38  }