-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,595 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package trie | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/NethermindEth/juno/core/felt" | ||
) | ||
|
||
// ProofSet represents a set of trie nodes used in a Merkle proof verification process. | ||
// Rather than relying on only either map of list, ProofSet provides both for the following reasons: | ||
// - map allows for unique node insertion | ||
// - list allows for ordered iteration over the proof nodes | ||
// It also supports concurrent read and write operations. | ||
type ProofSet struct { | ||
nodeSet map[felt.Felt]ProofNode | ||
nodeList []ProofNode | ||
size int | ||
lock sync.RWMutex | ||
} | ||
|
||
func NewProofSet() *ProofSet { | ||
return &ProofSet{ | ||
nodeSet: make(map[felt.Felt]ProofNode), | ||
} | ||
} | ||
|
||
func (ps *ProofSet) Put(key felt.Felt, node ProofNode) { | ||
ps.lock.Lock() | ||
defer ps.lock.Unlock() | ||
|
||
ps.nodeSet[key] = node | ||
ps.nodeList = append(ps.nodeList, node) | ||
ps.size++ | ||
} | ||
|
||
func (ps *ProofSet) Get(key felt.Felt) (ProofNode, bool) { | ||
ps.lock.RLock() | ||
defer ps.lock.RUnlock() | ||
|
||
node, ok := ps.nodeSet[key] | ||
return node, ok | ||
} | ||
|
||
func (ps *ProofSet) Size() int { | ||
ps.lock.RLock() | ||
defer ps.lock.RUnlock() | ||
|
||
return ps.size | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.