Archive for July, 2008

Removing myself from planet haskell

Monday, July 21st, 2008

Hi all,

I’ve asked to be removed from planet Haskell. There’s just too little Haskell related content on this blog these days for me to think it’s really appropriate for me to be on it. If you want to keep reading my blog, please subscribe directly.

They called me mad

Monday, July 21st, 2008

I haven’t written any fiction in ages, mostly because I kept dropping ideas as they were taking too long, so I’ve decided to start experimenting with microfiction as a format. Here’s the first of these.

They called me mad

I wake up on an operating table. I try to sit up, but I’m strapped down. Of course. Why is this never easy?

“Ah, Mr Michaels. You’re awake. Terribly sorry for the inconvenience, but we couldn’t have you interfering with the experiment. I’ll let you go as soon as we’re done here”.

I look at the speaker. An older man in a lab coat (why do they always wear lab coats? It’s not like they really need them. They’re always pristine white), fiddling around with some computer setup. My target.

There’s another table to my left. A dead woman on it - quite far gone. Well preserved, but withered and with a trace of decay. He’s further along than I’d hoped.

I strain against the bonds. No luck. I try to get to the knife in my hidden pocket, but it’s been taken. No way out but talking I guess.

“There’s still time to stop. I can guarantee you won’t be harmed.”

He looks genuinely puzzled.

“Why would I stop? Things are going so well”.

“What you’re doing is against nature! It will turn around and bite you if you don’t stop before it’s too late!”

“Do you live in a tree, Mr Michaels?”

“What?”

“Simple question. Do you live in a tree?”

“No. Why would I live in a tree?”

“Natural state of living for monkeys like ourselves. This modern housing, very unnatural.”

“That’s different”.

“Is it? Oh well, I suppose you’ve convinced me. I have seen the error of my ways and shall come quietly”.

“Really?”

“No, I’m afraid not. Anyway”, he said smiling brightly “all ready. We might as well begin”.

He presses a few buttons and a background humming noise I had hardly noticed raised in volume and pitch. My jaw dropped

“But how can you be ready? The storm isn’t for another two days!”

More bemused looks.

“Why would I need a storm? That sounds like a very unreliable way of working. I have a generator in the basement, and capacitors for storing the electric charge”.

I’m panicking now. I’d never let them get this close before. “Look, just stop! It’s all going to be horribly wrong!”

“Don’t be ridiculous. Do you think I haven’t tested this? I’m a scientist Mr Michaels. There is a process for these things. They called me mad, but the one accusation they never leveled was that my methods were insufficiently rigorous”.

“But you’ve never tested it on a human. Never on a being with a soul!”

He laughs. Not a cackle, just an amused little chuckle. I’ve heard a lot of mad laughs. I’m practically a connoisseur of a good diabolical laugh. Believe me, this chuckle is a lot worse.

“Of course I’ve tested it on a human. Tell me, Mr Michaels, did you think people normally wake up feeling quite so well rested after being shot in the face?”

I remember. I had my gun out, pointing at him, when there was a loud bang and then blackness. Oh god, he actually did it.

The humming raises to a fever pitch. There’s a crack, as if of thunder, and a bright white light fills the room. The dead woman sits up, decay fading and color and flesh returning to her. She smiles.

“Now, Mr Michaels, would you care to join Alice and myself for tea?”

java.lang.String#hashCode

Wednesday, July 16th, 2008

Apologies in advance. This is a really boring post.

For reasons you either know about by now or don’t care about, I was curious as to how well String’s hashCode was distributed (I suspected the answer was “not very”). I ran a few quick experiments to verify this.

For your amusement, here is a list of all hash collisions between alphanumeric strings of size 2: http://www.drmaciver.com/collisions.txt and here is a list of all which don’t collide with any others http://www.drmaciver.com/noncolliding.txt

Some statistics: There are 3844 alphanumeric strings of size 2. Of these 3570 collide with at least one other string. That is, 274 of these strings (or about 7% of them) *don’t* collide with something else.

Oh well. It’s a good thing no one would be stupid enough to rely on hashCode to distinguish the contents of two objects.

Edit: Additional facts I originally posted in the comments.

For what it’s worth, even fewer strings have unique hash codes for 3 characters. 3948 don’t collide, or about 1.6% of them.

This of course doesn’t mean that probability of a hash collision is really high. In reality it’s acceptably low. It’s just a demonstration that it’s not hard to find colliding pairs.

The following consist of all the String hash collisions contained in the sowpods scrabble dictionary:

  • isohel, epistolaries
  • righto, buzzards
  • hierarch, crinolines
  • inwork, hypercatalexes
  • wainages, presentencing
  • variants, gelato
  • misused, horsemints
  • trichothecenes, locular
  • pomatoes, eructation