Skip to content

Commit

Permalink
Update and add some comments
Browse files Browse the repository at this point in the history
Signed-off-by: Silas Davis <[email protected]>
  • Loading branch information
Silas Davis committed Aug 30, 2018
1 parent 41a1686 commit d125383
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions key_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (kf *KeyFormat) KeyBytes(segments ...[]byte) []byte {
panic(fmt.Errorf("length of segment %X provided to KeyFormat.Key() is longer than the %d bytes "+
"required by layout for segment %d", s, l, i))
}
// Big endian so pad on left if not given the full width for this segment
copy(key[n+(l-len(s)):n+l], s)
n += l
}
Expand Down Expand Up @@ -101,7 +102,7 @@ func scan(a interface{}, value []byte) {
case *[]byte:
*v = value
default:
panic(fmt.Errorf("KeyFormat.scan() does not support scanning value of type %T: %v", a, a))
panic(fmt.Errorf("KeyFormat scan() does not support scanning value of type %T: %v", a, a))
}
}

Expand All @@ -122,6 +123,6 @@ func format(a interface{}) []byte {
case []byte:
return v
default:
panic(fmt.Errorf("KeyFormat.format() does not support formatting value of type %T: %v", a, a))
panic(fmt.Errorf("KeyFormat format() does not support formatting value of type %T: %v", a, a))
}
}
12 changes: 6 additions & 6 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const (
)

var (
// All node keys are prefixed with this. This ensures no collision is
// possible with the other keys, and makes them easier to traverse.
nodeKeyFormat = NewKeyFormat('n', hashSize)
// All node keys are prefixed with the byte 'n'. This ensures no collision is
// possible with the other keys, and makes them easier to traverse. They are indexed by the node hash.
nodeKeyFormat = NewKeyFormat('n', hashSize) // n<hash>

// Orphans are keyed in the database by their expected lifetime.
// The first number represents the *last* version at which the orphan needs
// to exist, while the second number represents the *earliest* version at
// which it is expected to exist - which starts out by being the version
// of the node being orphaned.
orphanKeyFormat = NewKeyFormat('o', int64Size, int64Size, hashSize)
orphanKeyFormat = NewKeyFormat('o', int64Size, int64Size, hashSize) // o<last-version><first-version><hash>

// r/<version>
rootKeyFormat = NewKeyFormat('r', int64Size)
// Root nodes are indexed separately by their version
rootKeyFormat = NewKeyFormat('r', int64Size) // r<version>
)

type nodeDB struct {
Expand Down

0 comments on commit d125383

Please sign in to comment.