Wiki

Ticket #94 (new enhancement)

Opened 15 years ago

Last modified 11 years ago

cue hash

Reported by: Chuck Owned by:
Priority: major Milestone: Cobra 0.9
Component: Cobra Compiler Version: 0.8.0
Keywords: cue Cc:

Description

class X
    cue hash as int
        return ...
  • One of the few cues that is externally visible.
  • Implements GetHashCode() on .NET and hashCode() on JVM.
  • Requires is override or base.hash call.
  • def hash as int and def hash should give warnings about cues.

Change History

Changed 15 years ago by Chuck

  • type changed from defect to enhancement

Changed 11 years ago by kobi7

Hello,
What about something like this:
 http://stackoverflow.com/questions/763731/gethashcode-extension-method

meaning, getHashCode can be built-in, and if the user would like to override it, s/he can.
I suggest "baking-in" during compilation, all the instance variables, either as an object list, or a dictionary<string,object> (key=varName, value=varValue (the reference)).
(every class will have that built-in dictionary)

this can also be used for quick serialization (no need for reflection) and also for a clone method. (new, for i = 0 .. new.list.length -> new.list[i] = this.list[i], ret new)

Changed 11 years ago by kobi7

oops, the code should have been this.list[i].clone
the method name might be better as 'copy'

Changed 11 years ago by Charles

I doubt that it should be baked in as highly mutable classes rarely benefit or should even have a well defined hash code.

Note that we have HashCodeUtils? in the std lib (Cobra.Core):
http://cobra-language.com/trac/cobra/browser/cobra/trunk/Source/Cobra.Core/HashCodeUtils.cobra

which makes it easy to create a hash code from multiple sources.

Note: See TracTickets for help on using tickets.