Hardware algorithms for high-speed packet processing