Difference between revisions of "LlHash/ja"

From Second Life Wiki
Jump to navigation Jump to search
m
m
 
Line 2: Line 2:
|func_sleep=0.0|func_energy=10.0
|func_sleep=0.0|func_energy=10.0
|func=llHash|sort=Hash
|func=llHash|sort=Hash
|func_desc=Returns a 32bit hash for the provided string.  Returns 0 if the input string is empty.
|func_desc=指定された文字列の32ビットハッシュを返します。入力文字列が空の場合、0を返します。
|return_type=integer
|return_type=integer
|p1_type=string|p1_name=val|p1_desc=String to hash.
|p1_type=string|p1_name=val|p1_desc=ハッシュする文字列。
|p1_hover=String to hash.
|p1_hover=ハッシュする文字列。
|return_text=
|return_text=
|func_footnote=
|func_footnote=
|spec=
|spec=
The SDBM algorithm provides a good general purpose hash function with a fairly even distribution across the 32 bit space in the general case.
SDBMアルゴリズムは、一般的な用途に適したハッシュ関数で、一般的なケースでは32ビットスペース全体に対してかなり均等な分布を提供します。
The characters fed into the hash function are 32bit wide.
ハッシュ関数に供給される文字は32ビット幅です。


<source lang="cpp">
<source lang="cpp">
Line 42: Line 42:


|caveats=
|caveats=
This hash value is not cryptographically secure and should not be used as part of any security protocol.
このハッシュ値は暗号的に安全ではなく、セキュリティプロトコルの一部として使用すべきではありません。
SDBM provides a good distribution of hash values across its range, however with only
SDBMはハッシュ値をその範囲全体に均等に提供しますが、32ビットしかないため、衝突の可能性が非常に高いです(1000エントリの場合、衝突の確率は約1/10000です)。
32 bits the chance of a collision is unacceptably high.(with 1000 entries, the odds for a collision are about 1 in 10000.)
|examples=
|examples=
Given the combination of the object name and the owner's key generate a unique number.  This number could be used for things
オブジェクト名とオーナーのキーの組み合わせを与えて、ユニークな番号を生成します。この番号は、他のオブジェクトとの衝突の可能性が低いチャットチャネルを選択するなどの用途に使用できます。
like selecting a chat channel that has a low probability of colliding with another object.
<source lang="lsl2">
<source lang="lsl2">
integer pickIDForObject()
integer pickIDForObject()
Line 64: Line 62:
</source>
</source>
|helpers|related
|helpers|related
|also_functions=
{{LSL DefineRow|[[llOrd/ja]]|文字を順序数に変換する}}
{{LSL DefineRow|[[llOrd/ja]]|Convert a character into an ordinal}}
{{LSL DefineRow|[[llChar/ja]]|順序数を文字に変換する}}
{{LSL DefineRow|[[llChar/ja]]|Convert an ordinal into a character}}
|also_articles={{LSL DefineRow||{{wikipedia|ハッシュ関数の一覧}}|}}
|also_articles={{LSL DefineRow||{{wikipedia|List of hash functions}}|}}
{{LSL DefineRow||[https://preshing.com/20110504/hash-collision-probabilities/ Hash Collision Probabilities]|}}
{{LSL DefineRow||[https://preshing.com/20110504/hash-collision-probabilities/ Hash Collision Probabilities]|}}
|notes
|notes

Latest revision as of 15:09, 22 November 2023

要約

関数: integer llHash( string val );

指定された文字列の32ビットハッシュを返します。入力文字列が空の場合、0を返します。
integer で返します。

• string val ハッシュする文字列。

仕様

SDBMアルゴリズムは、一般的な用途に適したハッシュ関数で、一般的なケースでは32ビットスペース全体に対してかなり均等な分布を提供します。 ハッシュ関数に供給される文字は32ビット幅です。

U32 SDBMHash(const std::wstring &val)
{
    U32 hash(0);

    for(const wchar_t &c: val)
    {
        hash = c + (hash << 6) + (hash << 16) - hash;
    }
    return hash;
}

In LSL:

integer llSDBMHash(string value)
{
    integer hash = 0;
    integer index = 0;
    for (index = 0; index < llStringLength(value); ++index)
    {
        hash = llOrd(value, index) + (hash << 6) + (hash << 16) - hash;
    }
    
    return hash;
}

警告

このハッシュ値は暗号的に安全ではなく、セキュリティプロトコルの一部として使用すべきではありません。 SDBMはハッシュ値をその範囲全体に均等に提供しますが、32ビットしかないため、衝突の可能性が非常に高いです(1000エントリの場合、衝突の確率は約1/10000です)。

All Issues ~ Search JIRA for related Bugs

サンプル

オブジェクト名とオーナーのキーの組み合わせを与えて、ユニークな番号を生成します。この番号は、他のオブジェクトとの衝突の可能性が低いチャットチャネルを選択するなどの用途に使用できます。

integer pickIDForObject()
{
    /* Generate an arbitrary integer ID for the combination of the
     * object name and the ower's key.  This value could be used 
     * for selecting a chat/listen channel. 
     */
    string obj_name = llGetObjectName();
    key obj_owner = llGetOwner();
    
    integer hash = llHash(obj_name + (string)obj_owner);
    
    return hash;
}

関連項目

特記事項

Search JIRA for related Issues

Signature

function integer llHash( string val );
この翻訳は 原文 と比べて古いですか?間違いがありますか?読みにくいですか?みんなで 修正 していきましょう! (手順はこちら)
この項目はあなたにとって参考にならない項目ですか?もしかしたらLSL Wikiの関連した項目が参考になるかもしれません。