Tokyo Cabinet internal coherence checking code

The code after it has been reviewed by Bishwa, Micha and Sigurd.
Hope I didn't miss something ;)