MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / hash_string_with_offset

Function hash_string_with_offset

src/engine.rs:784–808  ·  view source on GitHub ↗
(key: &str, offset: u32, seed: u32)

Source from the content-addressed store, hash-verified

782}
783
784pub fn hash_string_with_offset(key: &str, offset: u32, seed: u32) -> Id {
785 let mut base: u32 = seed;
786 for b in key.bytes() {
787 base = base.wrapping_add(b as u32);
788 base = base.wrapping_add(base << 10);
789 base ^= base >> 6;
790 }
791 let mut hash = base;
792 hash = hash.wrapping_add(offset);
793 hash = hash.wrapping_add(hash << 10);
794 hash ^= hash >> 6;
795
796 hash = hash.wrapping_add(hash << 3);
797 base = base.wrapping_add(base << 3);
798 hash ^= hash >> 11;
799 base ^= base >> 11;
800 hash = hash.wrapping_add(hash << 15);
801 base = base.wrapping_add(base << 15);
802 Id {
803 id: hash.wrapping_add(1),
804 offset,
805 base_id: base.wrapping_add(1),
806 string_id: StringId::from_str(key),
807 }
808}
809
810fn hash_number(offset: u32, seed: u32) -> Id {
811 let mut hash = seed;

Callers 4

new_indexMethod · 0.85
new_index_seedMethod · 0.85
fromMethod · 0.85
debug_open_idiMethod · 0.85

Calls 1

bytesMethod · 0.80

Tested by

no test coverage detected