June 29, 2007

Twice Cooked Lamb

I decided to cook up some leg of lamb the other day and inspired by the way that hams are made I did a two part cooking process: Poaching the lamb before roasting it.

I poached the leg of lamb for about 2 hours in a liquor made up of:
  • Enough lamb and vegetable stock to cover the leg.
  • 2 cloves of garlic, crushed.
  • A cup of good quality red wine vinegar
  • A bouquet garni, made up of thyme, bay, marjoram and rosemary
  • 10 or so whole black peppercorns
I turned the lamb over about half way.

I then took the lamb out of the poaching liquor and placed it in a baking tray. I poured a little teriyaki and sunflower oil over the lamb before putting it in an hot oven (200c) for about half an hour.

Skim and boil the poaching liquor down to about a third to one half of it's original volume, allow to cool a little before tossing in some chopped mint.

Serve sliced with steamed vegetables and the starch of your choice - I like brown rice or quinoa - pouring the liquor and mint combination over.

The lamb will not be 'pink' in the modern idiom, but will be tender and very delicious.

June 27, 2007

Binary Manipulation in a String Friendly Language

Well, it's been a while since I blogged; and there's been a good reason since I had nothing worthwhile to say.

I've now got two things that I want to talk about; one is technical and the other is about cooking.

On to the technical. I'll blog the cooking in another entry.

Just recently at work I had cause to revisit an old technique that I hadn't used in years and I thought that it would be worth recording here.

We've been working with small binary fields in the database containing information that needs to be parsed. So far within the system we have kept much of the data-centric heavy lifting within the database but we were having difficulty with the binary information. The database provided a set of procedures for manipulating the binary information, but they were not very efficient. They were designed to work with extremely large pieces of binary information and tended to keep the binary information out of memory and in the database.

In general the database was far more designed to work with strings.

The work around was one that had been used when binary information needed to be manipulated by string-centric languages in the past. We converted the binary into a hexadecimal string. This allowed us to make use of in-memory string datatypes, and all the very efficient string manipulation tools that the database made available to us (but with the offsets doubled!). In this case we were fortunate as the database was able to do direct conversions from hex into numbers and then perform AND operations on the numbers as needed.

If that capability hadn't been there we could have used a further technique: to do a fast AND from hex you just build a look up table. The table provides a look up between the two hex values that you want to AND. For example a look up table that does just one hex digit at at time would look like:
A hexadecimal AND lookup table
HEX - AND0123456789ABCDEF
00000000000000000
10101010101010101
20022002200220022
30123012301230123
40004000400040004
50101454501014545
60022446600224466
70123456701234567
80000000088888888
90101010189898989
A0022002288AA88AA
B0123012389AB89AB
C00040004888C888C
D010145458989CDCD
E0022446688AACCEE
F0123456789ABCDEF


If you don't mind sacrificing more memory a 2 hex digit or greater lookup table can be created and of course a lot of the time you can distill the lookup further as you only need to do a single bit mask operation and so you would only need on one axis 1,2,4,8 etcetera.

By turning the binary manipulation into a hexadecimal one, we managed to increase the performance by 500%. Of course for really heavy binary manipulation you can't beat a binary friendly language but this technique can be an useful 'good enough' solution.