Skip to content

Commit

Permalink
Changed circuits.Stats type.
Browse files Browse the repository at this point in the history
  • Loading branch information
markkurossi committed Sep 1, 2021
1 parent 38961d8 commit 3d17c61
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 4 additions & 2 deletions circuit/circuit.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2019 Markku Rossi
// Copyright (c) 2019-2021 Markku Rossi
//
// All rights reserved.
//
Expand All @@ -23,6 +23,8 @@ const (
INV
)

type Stats [INV + 1]int

func (op Operation) String() string {
switch op {
case XOR:
Expand Down Expand Up @@ -149,7 +151,7 @@ type Circuit struct {
Inputs IO
Outputs IO
Gates []Gate
Stats map[Operation]int
Stats Stats
}

func (c *Circuit) String() string {
Expand Down
14 changes: 5 additions & 9 deletions circuit/parser.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2019 Markku Rossi
// Copyright (c) 2019-2021 Markku Rossi
//
// All rights reserved.
//
Expand Down Expand Up @@ -101,7 +101,7 @@ func ParseMPCLC(in io.Reader) (*Circuit, error) {
}

gates := make([]Gate, header.NumGates)
stats := make(map[Operation]int)
var stats Stats
var gate int
for gate = 0; ; gate++ {
op, err := r.ReadByte()
Expand Down Expand Up @@ -175,9 +175,7 @@ func ParseMPCLC(in io.Reader) (*Circuit, error) {
default:
return nil, fmt.Errorf("unsupported gate type %s", Operation(op))
}
count := stats[Operation(op)]
count++
stats[Operation(op)] = count
stats[Operation(op)]++
}

if uint32(gate) != header.NumGates {
Expand Down Expand Up @@ -348,7 +346,7 @@ func ParseBristol(in io.Reader) (*Circuit, error) {
}

gates := make([]Gate, numGates)
stats := make(map[Operation]int)
var stats Stats
var gate int
for gate = 0; ; gate++ {
line, err = readLine(r)
Expand Down Expand Up @@ -452,9 +450,7 @@ func ParseBristol(in io.Reader) (*Circuit, error) {
Output: outputs[0],
Op: op,
}
count := stats[op]
count++
stats[op] = count
stats[op]++
}
if gate != numGates {
return nil, fmt.Errorf("not enough gates: got %d, expected %d",
Expand Down
6 changes: 2 additions & 4 deletions compiler/circuits/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,9 @@ func (c *Compiler) Compile() *circuit.Circuit {
gate.Compile(c)
}

stats := make(map[circuit.Operation]int)
var stats circuit.Stats
for _, g := range c.compiled {
count := stats[g.Op]
count++
stats[g.Op] = count
stats[g.Op]++
}

result := &circuit.Circuit{
Expand Down

0 comments on commit 3d17c61

Please sign in to comment.