Ticket #94 (new enhancement)

Opened 10 years ago

Last modified 6 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:


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 10 years ago by Chuck

  • type changed from defect to enhancement

Changed 6 years ago by kobi7

What about something like this:

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 6 years ago by kobi7

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

Changed 6 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):

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

Note: See TracTickets for help on using tickets.