我的網站使用各種資源,從一個單一的域,例如:簡單的散列函數可變長度URL映射到數字(0 ... 3)
http://static.example.com/javascript/common.js
http://static.example.com/javascript/common.css
http://static.example.com/javascript/menu/menu.js
http://static.example.com/javascript/menu/menu.css
http://static.example.com/images/1804/logo/02000100.jpg
http://static.example.com/images/1804/headers/main/09400060.png
http://static.example.com/images/1804/headers/home/1101/06900200-01.jpg
http://static.example.com/images/1804/headers/home/1101/06900200-02.jpg
我需要一個非常簡單的字符串哈希函數映射這些網址爲數字,數字爲0,1,2和3.該算法應該是確定性和統一的。我已經標記了PHP的問題,但通用的答案是可以接受的。
你可能猜到了爲什麼我需要這個;我打算改變網址,例如:
http://0.static.example.com/javascript/common.js
http://2.static.example.com/javascript/common.css
我要說'的strlen($ STR)%$ num' ......這絕對快:) :) –
是快但不統一...看到包含單詞_headers_的網址?我將在一個頁面上使用它們中的大約15個,因此20個URL中的15個將具有散列= 3。 –
是的,無疑地,它更適用於更像人類的圖像名稱:) –