對字串進行哈希處理我想要 JMP 中的短字串哈希函數。 (我需要它從行數據創建匿名整數資料庫鍵。)
它不需要加密質量,只需要具有 64 位元(或 128 位元)結果並且具有相當低的衝突率。 我嘗試使用 Blob MD5() (截斷為 64 位元),但我不敢相信它有多慢。 (只需在 500,000 行的表上嘗試一下即可!)。有人在 JSL 中創建或連結到快速哈希演算法嗎? 使用輸入字串的某些函數來播種 JSL 的隨機數產生器怎麼樣? 我不需要 NIST 質量,但我確實需要一些快速且不太髒的東西,以便在所有平台上給出相同的結果。
您可以從 JSL 中呼叫現有的眾多 C++ 或 Java 雜湊演算法之一嗎? 如何?
PS 也許 JMP 14.1 可以在其標準庫中包含一些更好的雜湊函數。 包含 SHA 怎麼樣?
回覆:哈希字串順便說一句,這是我最終確定的解決方案:
// ==========================
// ::String Hash()
// ==========================
myStringHash = New Custom Function(
"Global",
"String Hash",
Function( {str, length = 64},
{bytes},
bytes = Match( length, 64, 8, 32, 4, Throw( "Bad argument in ::String Hash; hash length must be 64 (default) or 32." ) );
Subscript( Blob To Matrix( Blob Peek( Blob MD5( Char To Blob( str, "utf-8" ) ), 0, bytes ), "int", bytes, "little" ), 1 );
)
);
myStringHash << Description(
"Accepts a string as input, and returns an unsigned 64-bit or 32-bit integer hash of the string, generated by truncation of the (128-bit) MD5 hash of the input string.
The first parameter is the input string to be hashed.
The second, optional parameter is either the number 64 or the number 32. This selects whether the result will be a 64-bit (8-byte) integer, or a 32-bit (4-byte) integer. If not specified, the function defaults to 64-bit (8-byte). If a value other than 64 or 32 is entered, an error results."
);
myStringHash << Prototype( "::String Hash (string, <64|32>)" );
myStringHash << Example( "z = ::String Hash ( \!"This is a string\!" ); Show ( Format( z, 20, 0) )" );
myStringHash << Parameter( "String", "Input string" );
myStringHash << Parameter( "Number", "<64 or 32 (default is 64)>" );
myStringHash << Formula Category( "Database" );
Add Custom Functions( {myStringHash} );回覆:哈希字串克雷格,
也許我對 Blob MD5 太嚴格了。 它比我的機器上使用輸入字串的速度慢。 儘管如此,還是感謝您的客觀檢查。
約翰
回覆:哈希字串這在 1,000,000 行上運行大約需要 10 秒。
start = Tick Seconds();
dt = New Table( "Untitled",
Add Rows( 1e6 ),
New Column( "Column 1", Numeric, "Continuous", Format( "Best", 12 ), Formula( Row() ) ),
New Column( "Column 2", Character, "Nominal", Formula( Hex( Blob MD5( Char To Blob( Char( :Column 1 ) ) ) ) ) )
);
dt << runformulas; // run the formulas now, not in the background
stop = Tick Seconds();
Show( stop - start );
Using MD5 for hashUsing MD5 for hash使用 MD5 進行哈希
回覆:哈希字串感謝這個解決方案!
不幸的是,我使用的是Mac,所以我實際上無法使用vbs。 但現在我從你的例子中看到如何使用 RunProgram,我將嘗試讓它為 CityHash 工作( https://opensource.googleblog.com/2011/04/introducing-cityhash.html )。
回覆:哈希字串約翰·馬登,
我不是專家,這可能無法滿足您的需求。 下面是用於 SHA256 和 MD5 加密的 VBscript,可透過此連結找到它。
https://gist.github.com/jermity/557de47a978f7a7c4a74
我只知道Windows。複製附件,並將副檔名變更為 .vbs。 打開命令窗口,cd 到保存目錄並輸入 jerhash.vbs 以獲取使用語法。嵌入的腳本轉換狀態名稱。 此 vbs 腳本似乎不允許使用值清單。 52 個狀態名稱花了 8.2 秒,我確信連線運行程式的開銷會增加這一點。 附加的腳本顯示了建立 .bat 檔案的替代方法。 52 個項目的平均耗時約為 0.1 秒。 我沒有讀到該文件。 這是另一種方法。 離線產生 500k 然後讀入檔案。
這就是我的全部。問候。

mytbl = New Table("testit", New Column("States", Character,
Values({"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
"District of Columbia", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico",
"New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon",
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
"Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin",
"Wyoming"}) ), NewColumn("Code",Character)
);
t1 = tick seconds();
for(i=1, i<=nrow(mytbl), i++,
:Code[i] = Trim(RunProgram(Executable("cscript"),
Options(EvalInsert("\[//nologo c:\temp\jerhash.vbs /A:sha256 /S:"^:States[i]^"]\") ),
ReadFunction("text")
));
);
t2= tickseconds();
show(t2-t1);