Project

Profile

Help

Bug #3167

Problems with QName hash-codes in trieWithCollation()

Added by John Lumley over 1 year ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Sprint/Milestone:
-
Start date:
2017-03-14
Due date:
% Done:

100%

Applies to JS Branch:
Trunk
Fix Committed on JS Branch:
Trunk
Fixed in JS Release:
SEF Generated with:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

In cases where the key for a map entry is a QName@, rather than 'string-like', a hash function wasn't being assigned. This requires some careful alterations to the logic in @Compare.js#trieWithCollation()

History

#1 Updated by Michael Kay about 1 year ago

There are two further problems here:

(a) for non-string keys, we are treating keys as equal if their hash codes are equal.

(b) For QNames, we have a very poor hash function, specifically:

return this.uri.substring(this.uri.length - 3) + ":" + this.local.substring(0, 3);

A better one would be

return this.uri.substring(this.uri.length - 3) + ":" + new XdmString(this.local).hashCode()

Test case: try grouping elements by node-name() where there are elements whose names don't vary in the first four characters.

#2 Updated by Michael Kay about 1 year ago

  • Assignee changed from Michael Kay to Debbie Lockett

#3 Updated by Debbie Lockett about 1 year ago

  • Found in version deleted (1.0.0)

trieWithCollation is new development code since the release of Saxon-JS 1.0.0.

It may be worth testing whether the same bug arises when grouping by element name using Saxon-JS 1.0.0. Or whether it is just now broken in the development version. (For now I'm declassifying this bug from being 'found in version Saxon-JS 1.0.0'.)

#4 Updated by Debbie Lockett about 1 year ago

  • Status changed from New to Resolved

XSLT 3.0 test for-each-group-082 added.

Saxon-JS code fixes:

  1. Atomic.XdmQName.hashCode updated as suggested in (b).

  2. New method matchKey() added to all classes for primitive types. matchKey() returns a string representation of the value, such that

![]((a.equals(b)) implies (matchKey(a) ) i.e. the matchKey strings are always different for different values. (Note that this condition is not always true for hash codes, so they are not always suitable.)

matchKey() can then be used by matchFn() in Compare.trieWithCollation.

#5 Updated by Debbie Lockett 11 months ago

  • Applies to branch deleted (9.8)
  • Applies to JS Branch Trunk added
  • Fix Committed on JS Branch Trunk added

#6 Updated by Debbie Lockett 11 months ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 1.0.1

Bug fix applied in Saxon-JS 1.0.1 maintenance release.

Please register to edit this issue

Also available in: Atom PDF Tracking page