rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
676 stars 127 forks source link

Why does Term.hashCode() always return 0? #306

Closed rorlic closed 1 year ago

rorlic commented 1 year ago

I see the hashCode test always expect it to be 0:

  describe('A Term instance', () => {
    it('has an integer hashCode', () => {
      new Term().hashCode().should.equal(0);
    });
  });

Why is that?

The rules for a hash code are:

So I understand that the above implementation is in fact perfectly correct, but I would not expect all of them to return the same hash :wink:

RubenVerborgh commented 1 year ago

Hi @rorlic,

That's purely for Immutable.js compatibility:

https://github.com/rdfjs/N3.js/blob/b7e9a8414941f61d88db01f8ca1cb0d5205bb225/src/N3DataFactory.js#L49-L53

We don't want to require an expensive hashing library on the client.