Peace For All

August 29, 2006

Power comes at a price

Filed under: Programming — Devlin Bentley @ 2:47 pm

Going through the Python tutorial again:

Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key.

Well OK, that sounds reasonable.  You can’t use an object as a key if it keeps changing, right?

Oh wait, I can in Java.  I define a Hash function, done.

I have only had to use this once, and it was for a rather baroque situation, but it was rather cool that I could do it, and fairly simple as well.  Just pick which non-mutable instance variables of the class that should be used to generate a hash value, and shove them into a hash function.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: