Code Kata: Unrolled Linked List (in C)

The other day I needed a linked list for the umpteenth time, and instead of going with the old (data, next) pairs, I decided I wanted something a bit more efficient, like an unrolled linked list. This also provided a good opportunity to use the CuTest unit testing framework and do some test-first development.

The result is pretty nice, testing actually found a small bug, despite the fact that I was sure can do linked lists in my sleep, and I was so pleased with the performance characteristics (better cache efficiency and far fewer allocations) that I replaced all the lists in Eressea with it.

Code sample:

quicklist *q, *ql = 0;
int i;
// insert element at index:
ql_insert(ql, 0, foo);
ql_insert(ql, 0, bar);
assert(ql_get(ql, 1)==foo);
assert(ql_length(ql)==2);
// push element at end, get indexed element:
ql_push(ql, baz);
assert(ql_get(ql, 2)==baz);
// iterate over list:
for (q=ql,i=0;q;ql_advance(&ql, &i, 1)) {
  printf("%p ", ql_get(q, i));
}

Code is on github. Use as you please.

Linkage Six

Today I’ve got a list of Difficult English Words you can use to impress your friends with and really stand out as the nerd you are. If you’re also a coder then you may appreciate this collection of bit twiddling hacks — there’s something there for everyone, and of course it also has the famous HAKMEM bit counting algorithm. City Shrinker makes large things look very small. It’s hard to believe that these aren’t models. For the audiophiles and cat-lovers, here’s Purrcast, the sound of cats purring. And last, but not least, this man is my new hero.

Quad Power!

I caved in and bought a new PC. The thing that really strikes me is how long it takes to set up a new PC with Windows compared to Ubuntu. In any modern Linux distribution, I just insert the CD, select the software I want from a huge list and let it do the magic while I do something else. And in an hour, everything’s done.

Meanwhile’ I’m in the middle of day two of my Windows installation. Windows itself is a hassle to install: Missing RAID drivers mean I have to bake a new ISO image and can’t use the regular install CD. Which starts by finding a PC with a CD burner, finding the drivers on the net (because Intel only included 32 bit drivers, hooray), finding a floppy drive in the basement because the drivers are distributed as an executable that formats a floppy (oh, how convenient is that?), building the CD, blabla…
Continue reading

Going Native

A list of things I have done in my attempt to become Norwegian.

  • learned Norwegian
  • learned to love brunost (not hard, the stuff is great).
  • cut myself with an Ostehøvel
  • eaten Lutefisk for Christmas dinner.
  • eaten Ribbe for Christmas
  • bought a suit and worn it on 17th of May
  • watched barnetoget
  • shared an appartment with Norway’s sexiest woman (according to Vi Menn)
  • watched all episodes of ‘Pompel og Pilt’
  • bumped into the King at an art exhibit (okay, that was accidental)
  • learnt to snowboard
  • gone cross country skiing in frogner park
  • watched a lot of ‘Typisk Norsk’ episodes
  • spent an entire afternoon watching curling
  • gone to several hundreds of ‘visninger’
  • eaten Rømmegrøt
  • made fun of the Danish language
  • gone sledding on korketrekkeren (several times)
  • been on Galdhøpiggen
  • gone over bessegen
  • bicycled from Oslo to Stavanger
  • signed myself up for styrkeprøven
  • joined a gym
  • gone on countless hytteturer, especially around easter
  • learned about kardemomme by
  • learned about janteloven
  • been in a reality show on national TV (only for a little while)
  • started a sizeable colletion of imported alcohol in my kitchen
  • complained about beer prices
  • learned to accept beer prices as a fact of life

That’s just off the top of my head, the list is woefully incomplete. And even after all that, I still feel I have a long way to go. My list of things that I haven’t done is probably as long. And the list of things I’m not even aware of that are part of every Norwegian’s common culture is even longer. It’s hard to become truly integrated.

[Listening to: Nordaførr – Vårvisa – Halvdan Sivertsen]