MCPcopy Create free account
hub / github.com/antchfx/xpath / getHashCode

Function getHashCode

query.go:1371–1414  ·  view source on GitHub ↗
(n NodeNavigator)

Source from the content-addressed store, hash-verified

1369}
1370
1371func getHashCode(n NodeNavigator) uint64 {
1372 var sb bytes.Buffer
1373 switch n.NodeType() {
1374 case AttributeNode, TextNode, CommentNode:
1375 sb.WriteString(n.LocalName())
1376 sb.WriteByte('=')
1377 sb.WriteString(n.Value())
1378 // https://github.com/antchfx/htmlquery/issues/25
1379 d := 1
1380 for n.MoveToPrevious() {
1381 d++
1382 }
1383 sb.WriteByte('-')
1384 sb.WriteString(strconv.Itoa(d))
1385 for n.MoveToParent() {
1386 d = 1
1387 for n.MoveToPrevious() {
1388 d++
1389 }
1390 sb.WriteByte('-')
1391 sb.WriteString(strconv.Itoa(d))
1392 }
1393 case ElementNode:
1394 sb.WriteString(n.Prefix() + n.LocalName())
1395 d := 1
1396 for n.MoveToPrevious() {
1397 d++
1398 }
1399 sb.WriteByte('-')
1400 sb.WriteString(strconv.Itoa(d))
1401
1402 for n.MoveToParent() {
1403 d = 1
1404 for n.MoveToPrevious() {
1405 d++
1406 }
1407 sb.WriteByte('-')
1408 sb.WriteString(strconv.Itoa(d))
1409 }
1410 }
1411 h := fnv.New64a()
1412 h.Write(sb.Bytes())
1413 return h.Sum64()
1414}
1415
1416func getNodePosition(q query) int {
1417 type Position interface {

Callers 4

SelectMethod · 0.85
SelectMethod · 0.85
selectNodesFunction · 0.85
Benchmark_GetHashCodeFunction · 0.85

Calls 7

WriteStringMethod · 0.80
NodeTypeMethod · 0.65
LocalNameMethod · 0.65
ValueMethod · 0.65
MoveToPreviousMethod · 0.65
MoveToParentMethod · 0.65
PrefixMethod · 0.65

Tested by 2

selectNodesFunction · 0.68
Benchmark_GetHashCodeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…