background preloader

Algorithm

Facebook Twitter

A Hash Function for Hash Table Lookup. Abstract I offer you a new hash function for hash table lookup that is faster and more thorough than the one you are using now. I also give you a way to verify that it is more thorough. All the text in this color wasn't in the 1997 Dr Dobbs article. The code given here are all public domain. The Hash Over the past two years I've built a general hash function for hash table lookup. These old hashes defined my requirements: The keys are unaligned variable-length byte arrays. Without further ado, here's the fastest hash I've been able to design that meets all the requirements. Update: I'm leaving the old hash in the text below, but it's obsolete, I have faster and more thorough hashes now. . (2006) is about 2 cycles/byte, works well on 32-bit platforms, and can produce a 32 or 64 bit hash. Most hashes can be modeled like this: In the new hash, mix() takes 3n of the 6n+35 instructions needed to hash n bytes.

Three tricks promote speed: How do we test that? Hacker's Delight. Jones on Binary to Decimal Conversion. Index Introduction Programmers on binary computers have always faced computational problems when dealing with textual input-output because of our convention that printed numeric data should be represented in base 10. These problems have never been insurmountable, but they are particularly annoying when writing programs for machines with limited capacity in their arithmetic units. Suppose, for example, you have an unsigned binary number that you wish to print out in decimal form. Void putdec( unsigned int n ) { unsigned int rem = n % 10; unsigned int quot = n / 10; if (quot > 0) putdec( quot ); putchar( rem + '0' ); } The problem with this C code is that it assumes that the computer's arithmetic unit is sufficiently large to handle the entire number n, and it assumes that the arithmetic unit can conveniently do integer division yielding both a quotient and a remainder.

The Basic Idea n |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _| |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| | n | n | n | n | 3 2 1 0 0 ≤ a0 ≤ 243. Jones on reciprocal multiplication. Index Introduction There are many reasons to omit integer division from the instruction set of a computer. In the early days of computing, the cost of this hardware was a dominant factor, and it still dominates in the world of programmable microcontrollers such as the PIC family of chips made by Microchip. Today, the difficulties cleanly integrating divide hardware into pipelined systems has led to the omission of integer divide hardware from a surprising number of high performance microprocessors and DSP chips. Such an omission can only be justified if division can be done efficiently in software, and fortunately, this is the case! Elimination of multiply instructions is itself desirable. The goal of the remainder of this presentation is to investigate how division by constants, particularly by 10, can be efficiently coded for unsigned integers on a machine without using multiply or divide instructions; on the way, we will briefly visit efficient multiplication by constants.

Furthermore: Bloom filter. Bloomier filter. Knuth: Recent News. [click here to zip down to the schedule of public lectures] Financial Fiasco Leading banks and investment funds have been foundering, because of bad debts and lack of trust; and other, less well-known kinds of fiscal chaos are also on the horizon. For example, due to an unfixable security flaw in the way funds are now transferred electronically, worldwide, it is no longer safe to write personal checks. A criminal who sees the numbers that are printed at the bottom of any check that you write can use that information to withdraw all the money from your account. He or she can do this in various ways, without even knowing your name --- for example by creating an ATM card, or by impersonating a bank in some country of the world where safeguards are minimal, or by printing a document that looks like a check.

The account number and routing information are all that international financial institutions look at before deciding to transfer funds from one account to another. Section 7 Section 7.1.1.