Skip to content

Commit

Permalink
more docs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Nov 6, 2024
1 parent bf2f60e commit a907f8a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
32 changes: 16 additions & 16 deletions pkg/trie/triedb/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ func (ri *TrieDBRawIterator[H, Hasher]) NextItem() (*TrieItem, error) {
}
}

// / Fetches the next key.
// /
// / Must be called with the same `db` as when the iterator was created.
// Fetches the next key.
//
// Must be called with the same `db` as when the iterator was created.
func (ri *TrieDBRawIterator[H, Hasher]) NextKey() ([]byte, error) {
for {
rawItem, err := ri.nextRawItem(true)
Expand Down Expand Up @@ -499,20 +499,20 @@ type TrieItem struct {
Value []byte
}

// / A trie iterator that also supports random access (`seek()`).
// A trie iterator that also supports random access (`seek()`).
type TrieIterator[H hash.Hash, Item any] interface {
Seek(key []byte) error
Next() (Item, error)
// Items() iter.Seq2[Item, error]
}

// / Iterator for going through all values in the trie in pre-order traversal order.
// Iterator for going through all values in the trie in pre-order traversal order.
type TrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]] struct {
db *TrieDB[H, Hasher]
rawIter TrieDBRawIterator[H, Hasher]
}

// / Create a new iterator.
// Create a new iterator.
func NewTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]](
db *TrieDB[H, Hasher],
) (*TrieDBIterator[H, Hasher], error) {
Expand All @@ -526,7 +526,7 @@ func NewTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]](
}, nil
}

// / Create a new iterator, but limited to a given prefix.
// Create a new iterator, but limited to a given prefix.
func NewPrefixedTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]](
db *TrieDB[H, Hasher], prefix []byte,
) (*TrieDBIterator[H, Hasher], error) {
Expand All @@ -540,9 +540,9 @@ func NewPrefixedTrieDBIterator[H hash.Hash, Hasher hash.Hasher[H]](
}, nil
}

// / Create a new iterator, but limited to a given prefix.
// / It then do a seek operation from prefixed context (using `seek` lose
// / prefix context by default).
// Create a new iterator, but limited to a given prefix.
// It then do a seek operation from prefixed context (using `seek` lose
// prefix context by default).
func NewPrefixedTrieDBIteratorThenSeek[H hash.Hash, Hasher hash.Hasher[H]](
db *TrieDB[H, Hasher], prefix []byte, startAt []byte,
) (*TrieDBIterator[H, Hasher], error) {
Expand Down Expand Up @@ -582,12 +582,12 @@ func (tdbi *TrieDBIterator[H, Hasher]) Items() iter.Seq2[TrieItem, error] {
}
}

// / Iterator for going through all of key with values in the trie in pre-order traversal order.
// Iterator for going through all of key with values in the trie in pre-order traversal order.
type TrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]] struct {
rawIter TrieDBRawIterator[H, Hasher]
}

// / Create a new iterator.
// Create a new iterator.
func NewTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]](
db *TrieDB[H, Hasher],
) (*TrieDBKeyIterator[H, Hasher], error) {
Expand All @@ -600,7 +600,7 @@ func NewTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]](
}, nil
}

// / Create a new iterator, but limited to a given prefix.
// Create a new iterator, but limited to a given prefix.
func NewPrefixedTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]](
db *TrieDB[H, Hasher], prefix []byte,
) (*TrieDBKeyIterator[H, Hasher], error) {
Expand All @@ -613,9 +613,9 @@ func NewPrefixedTrieDBKeyIterator[H hash.Hash, Hasher hash.Hasher[H]](
}, nil
}

// / Create a new iterator, but limited to a given prefix.
// / It then do a seek operation from prefixed context (using `seek` lose
// / prefix context by default).
// Create a new iterator, but limited to a given prefix.
// It then do a seek operation from prefixed context (using `seek` lose
// prefix context by default).
func NewPrefixedTrieDBKeyIteratorThenSeek[H hash.Hash, Hasher hash.Hasher[H]](
db *TrieDB[H, Hasher], prefix []byte, startAt []byte,
) (*TrieDBKeyIterator[H, Hasher], error) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/trie/triedb/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func (l *TrieLookup[H, Hasher, QueryItem]) recordAccess(access TrieAccess) {
}
}

// / Look up the merkle value (hash) of the node that is the closest descendant for the provided
// / key.
// /
// / When the provided key leads to a node, then the merkle value (hash) of that node
// / is returned. However, if the key does not lead to a node, then the merkle value
// / of the closest descendant is returned. `None` if no such descendant exists.
// Look up the merkle value (hash) of the node that is the closest descendant for the provided
// key.
//
// When the provided key leads to a node, then the merkle value (hash) of that node
// is returned. However, if the key does not lead to a node, then the merkle value
// of the closest descendant is returned. `None` if no such descendant exists.
func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant(
fullKey []byte, nibbleKey nibbles.Nibbles,
) (MerkleValue[H], error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/trie/triedb/node_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var EmptyNode = []byte{0}

// StorageHandle is a pointer to a node contained in `NodeStorage`
// StorageHandle is a pointer to a node contained in nodeStorage
type storageHandle int

// NodeHandle is an enum for the different types of nodes that can be stored in
Expand Down
16 changes: 8 additions & 8 deletions pkg/trie/triedb/triedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (t *TrieDB[H, Hasher]) Set(key, value []byte) error {
}

// insertAt inserts the given key / value pair into the node referenced by the
// node handle `handle`
// node handle
func (t *TrieDB[H, Hasher]) insertAt(
handle NodeHandle,
keyNibbles *nibbles.Nibbles,
Expand Down Expand Up @@ -359,7 +359,7 @@ type inspectResult struct {
changed bool
}

// inspect inspects the given node `stored` and calls the `inspector` function
// inspect inspects the given node stored and calls the inspector function
// then returns the new node and a boolean indicating if the node has changed
func (t *TrieDB[H, Hasher]) inspect(
stored StoredNode,
Expand Down Expand Up @@ -536,7 +536,7 @@ func combineKey(start nodeKey, end nodeKey) nodeKey {
return start
}

// removeInspector removes the key node from the given node `stored`
// removeInspector removes the key node from the given node stored
func (t *TrieDB[H, Hasher]) removeInspector(
stored Node, keyNibbles *nibbles.Nibbles, oldValue *nodeValue,
) (action, error) {
Expand Down Expand Up @@ -624,7 +624,7 @@ func (t *TrieDB[H, Hasher]) removeInspector(
}
}

// insertInspector inserts the new key / value pair into the given node `stored`
// insertInspector inserts the new key / value pair into the given node stored
func (t *TrieDB[H, Hasher]) insertInspector(
stored Node, keyNibbles *nibbles.Nibbles, value []byte, oldValue *nodeValue,
) (action, error) {
Expand Down Expand Up @@ -833,7 +833,7 @@ func (t *TrieDB[H, Hasher]) lookupNode(hash H, key nibbles.Prefix) (storageHandl

return newNodeFromEncoded[H](hash, encodedNode, &t.storage)
}
// We only check the `cache` for a node with `get_node` and don't insert
// We only check the cache for a node with GetNode and don't insert
// the node if it wasn't there, because in substrate we only access the node while computing
// a new trie (aka some branch). We assume that this node isn't that important
// to have it being cached.
Expand Down Expand Up @@ -1171,16 +1171,16 @@ type MerkleValues[H any] interface {
MerkleValue[H]
}

// Either the `hash` or `value` of a node depending on its size.
// Either the hash or value of a node depending on its size.
//
// If the size of the node `value` is bigger or equal than `MAX_INLINE_VALUE` the `hash` is
// If the size of the node value is bigger or equal than 32 bytes the hash is
// returned.
type MerkleValue[H any] interface {
isMerkleValue()
}

// The merkle value is the node data itself when the
// node data is smaller than `MAX_INLINE_VALUE`.
// node data byte length is less than or equal to 32 bytes.
//
// Note: The case of inline nodes.
type NodeMerkleValue []byte
Expand Down

0 comments on commit a907f8a

Please sign in to comment.