add custom hash for RootedVertexID (#3070)

* add custom `hash` for `RootedVertexID`

There's no benefit hashing `root` since `vid` is already unique and the
"default" hash is not free - this trivially brings a small perf boost to
one of the key lookup tables in aristo_layers.

* lint
This commit is contained in:
Jacek Sieka 2025-02-14 15:50:46 +01:00 committed by GitHub
parent e666eb52b0
commit b6584153ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,5 @@
# nimbus-eth1 # nimbus-eth1
# Copyright (c) 2023-2024 Status Research & Development GmbH # Copyright (c) 2023-2025 Status Research & Development GmbH
# Licensed under either of # Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0) # http://www.apache.org/licenses/LICENSE-2.0)
@ -130,9 +130,6 @@ func `$`*(vid: VertexID): string =
"$" & (if vid == VertexID(0): "ø" "$" & (if vid == VertexID(0): "ø"
else: vid.uint64.toHex.strip(trailing=false,chars={'0'}).toLowerAscii) else: vid.uint64.toHex.strip(trailing=false,chars={'0'}).toLowerAscii)
func `$`*(rvid: RootedVertexID): string =
$rvid.root & "/" & $rvid.vid
func `==`*(a: VertexID; b: static[uint]): bool = (a == VertexID(b)) func `==`*(a: VertexID; b: static[uint]): bool = (a == VertexID(b))
# Scalar model extension as in `IntervalSetRef[VertexID,uint64]` # Scalar model extension as in `IntervalSetRef[VertexID,uint64]`
@ -140,6 +137,15 @@ func `+`*(a: VertexID; b: uint64): VertexID = (a.uint64+b).VertexID
func `-`*(a: VertexID; b: uint64): VertexID = (a.uint64-b).VertexID func `-`*(a: VertexID; b: uint64): VertexID = (a.uint64-b).VertexID
func `-`*(a, b: VertexID): uint64 = (a.uint64 - b.uint64) func `-`*(a, b: VertexID): uint64 = (a.uint64 - b.uint64)
func `==`*(a, b: RootedVertexID): bool {.inline.} =
a.vid == b.vid
func hash*(rvid: RootedVertexID): Hash {.inline.} =
hash(rvid.vid)
func `$`*(rvid: RootedVertexID): string =
$rvid.root & "/" & $rvid.vid
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Public helpers: `PathID` ordered scalar data model # Public helpers: `PathID` ordered scalar data model
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -9,7 +9,7 @@
# at your option. This file may not be copied, modified, or distributed # at your option. This file may not be copied, modified, or distributed
# except according to those terms. # except according to those terms.
## This module implements Ethereum Wire Protocol version 67, `eth/67`. ## This module implements Ethereum Wire Protocol version 68, `eth/68`.
## Specification: ## Specification:
## `eth/68 <https://github.com/ethereum/devp2p/blob/master/caps/eth.md>`_ ## `eth/68 <https://github.com/ethereum/devp2p/blob/master/caps/eth.md>`_