英語版
このページの英語版を見る
std.digest.crc
巡回冗長検査(32ビット)の実装。
カテゴリー | 関数 |
---|---|
Template API | CRCCRC32CRC64ECMACRC64ISO |
OOP API | CRC32DigestCRC64ECMADigestCRC64ISODigest |
Helpers | crcHexStringcrc32Ofcrc64ECMAOfcrc64ISOOf |
注釈: CRCは通常MSBが先に表示される。 CRCは通常、MSBを先頭にして表示される。を使用する場合 std.digest.toHexStringを使用した場合、結果は予期しない の順になる。そのため std.digest.toHexStringオプションのorderパラメータ を使う。の crcHexString を使うこともできる。
License:
Authors:
Pavel "EvilOne" Minayev, Alex Rønne Petersen, Johannes Pfau
参考文献 CRCに関するウィキペディア
Standards:
IEEE CRC32の「一般的な」バリアントを実装する。
(LSBファーストオーダー、初期値uint.max、補数結果)
CTFE ダイジェストはCTFEでは機能しない
Examples:
//テンプレートAPI import std.digest.crc; ubyte[4] hash = crc32Of("The quick brown fox jumps over the lazy dog"); writeln(crcHexString(hash)); // "414FA339" //データの供給 ubyte[1024] data; CRC32 crc; crc.put(data[]); crc.start(); //再度開始する crc.put(data[]); hash = crc.finish();
Examples:
//OOP API import std.digest.crc; auto crc = new CRC32Digest(); ubyte[] hash = crc.digest("The quick brown fox jumps over the lazy dog"); assert(crcHexString(hash) == "414FA339"); //352441c2 //データを供給する ubyte[1024] data; crc.put(data[]); crc.reset(); //再度開始する crc.put(data[]); hash = crc.finish();
- alias
CRC32
= CRC!(32u, 3988292384LU).CRC; - テンプレートAPIのCRC32実装。 テンプレートAPIとOOP APIの違いについてはstd.digest を参照のこと。
- alias
CRC64ECMA
= CRC!(64u, 14514072000185962306LU).CRC; - テンプレートAPI CRC64-ECMAの実装。 テンプレートと OOP API の違いについてはstd.digest を参照のこと。
- alias
CRC64ISO
= CRC!(64u, 15564440312192434176LU).CRC; - テンプレートAPI CRC64-ISOの実装。 テンプレートと OOP API の違いについてはstd.digest を参照のこと。
- struct
CRC
(uint N, ulong P) if (N == 32 || N == 64); - CRC32 および CRC64 の実装に使用される汎用テンプレート API。Nパラメータはハッシュのサイズをビット単位で示す。 パラメータPは、縮小に使用する多項式を指定する。 CRC32、CRC65ECMA、CRC64ISOのエイリアスを使用すると便利である。 を使用すると便利である。 テンプレートとOOP APIの違いについてはstd.digest を参照のこと。Examples:
//単純な例として、crc32Ofヘルパー関数を使用して文字列をハッシュ化する ubyte[4] hash32 = crc32Of("abc"); //ハッシュ文字列を取得してみよう writeln(crcHexString(hash32)); // "352441C2" // CRC64を繰り返す ubyte[8] hash64ecma = crc64ECMAOf("abc"); writeln(crcHexString(hash64ecma)); // "2CD8094A1A277627" ubyte[8] hash64iso = crc64ISOOf("abc"); writeln(crcHexString(hash64iso)); // "3776C42000000000"
Examples:ubyte[1024] data; //基本APIを使用する CRC32 hash32; CRC64ECMA hash64ecma; CRC64ISO hash64iso; //ここでデータを初期化する... hash32.put(data); ubyte[4] result32 = hash32.finish(); hash64ecma.put(data); ubyte[8] result64ecma = hash64ecma.finish(); hash64iso.put(data); ubyte[8] result64iso = hash64iso.finish();
Examples://テンプレートの機能を使おう: //注釈: CRC32を関数に渡す場合は、参照渡しでなければならない! void doSomething(T)(ref T hash) if (isDigest!T) { hash.put(cast(ubyte) 0); } CRC32 crc32; crc32.start(); doSomething(crc32); writeln(crcHexString(crc32.finish())); // "D202EF8D" // CRC64を繰り返す CRC64ECMA crc64ecma; crc64ecma.start(); doSomething(crc64ecma); writeln(crcHexString(crc64ecma.finish())); // "1FADA17364673F59" CRC64ISO crc64iso; crc64iso.start(); doSomething(crc64iso); writeln(crcHexString(crc64iso.finish())); // "6F90000000000000"
- pure nothrow @nogc @trusted void
put
(scope const(ubyte)[]data
...); - pure nothrow @nogc @safe void
start
(); - CRC32 ダイジェストの初期化に使用する。
注釈: このCRC32ダイジェストの実装では、デフォルトの構築後にstartを呼び出す を呼び出す必要はない。startの呼び出しは、ダイジェストをリセットするためにのみ必要である。
異なるダイジェスト型を扱う一般的なコードは、常にstartを呼び出すべきである。 - pure nothrow @nogc @safe R
finish
(); - 終了したCRCハッシュを返す。これはまた startを呼び出す。 内部状態をリセットする。
- const pure nothrow @nogc @safe R
peek
(); - finish のように動作するが、内部状態はリセットされない。 peekを呼び出した後、このCRCにデータを入れ続けることができる。
- ubyte[4]
crc32Of
(T...)(Tdata
); - これは std.digest.digestの便利なエイリアスだ。 CRC32実装を使用するための便利な別名である。Parameters:
T data
InputRange ElementType 、暗黙のうちに に暗黙的に変換可能である。 に暗黙的に変換可能である。ubyte ubyte[] ubyte[num] Returns:データのCRC32Examples:ubyte[] data = [4,5,7,25]; writeln(data.crc32Of); // [167, 180, 199, 131] import std.utf : byChar; writeln("hello"d.byChar.crc32Of); // [134, 166, 16, 54] ubyte[4] hash = "abc".crc32Of(); writeln(hash); // digest!CRC32("ab", "c") import std.range : iota; enum ubyte S = 5, F = 66; writeln(iota(S, F).crc32Of); // [59, 140, 234, 154]
- ubyte[8]
crc64ECMAOf
(T...)(Tdata
); - これは std.digest.digestこれは CRC64-ECMA実装を使うための便利な別名である。Parameters:
T data
InputRange ElementType 、暗黙のうちに に暗黙的に変換可能である。 に暗黙的に変換可能である。ubyte ubyte[] ubyte[num] Returns:データのCRC64-ECMAExamples:ubyte[] data = [4,5,7,25]; writeln(data.crc64ECMAOf); // [58, 142, 220, 214, 118, 98, 105, 69] import std.utf : byChar; writeln("hello"d.byChar.crc64ECMAOf); // [177, 55, 185, 219, 229, 218, 30, 155] ubyte[8] hash = "abc".crc64ECMAOf(); writeln("abc".crc64ECMAOf); // [39, 118, 39, 26, 74, 9, 216, 44] writeln(hash); // digest!CRC64ECMA("ab", "c") import std.range : iota; enum ubyte S = 5, F = 66; writeln(iota(S, F).crc64ECMAOf); // [6, 184, 91, 238, 46, 213, 127, 188]
- ubyte[8]
crc64ISOOf
(T...)(Tdata
); - これは std.digest.digestこれは CRC64-ISO実装を使用するための便宜的な別名である。Parameters:
T data
InputRange ElementType 、暗黙のうちに に暗黙的に変換可能である。 に暗黙的に変換可能である。ubyte ubyte[] ubyte[num] Returns:データのCRC64-ISOExamples:ubyte[] data = [4,5,7,25]; writeln(data.crc64ISOOf); // [0, 0, 0, 80, 137, 232, 203, 120] import std.utf : byChar; writeln("hello"d.byChar.crc64ISOOf); // [0, 0, 16, 216, 226, 238, 62, 60] ubyte[8] hash = "abc".crc64ISOOf(); writeln("abc".crc64ISOOf); // [0, 0, 0, 0, 32, 196, 118, 55] writeln(hash); // digest!CRC64ISO("ab", "c") import std.range : iota; enum ubyte S = 5, F = 66; writeln(iota(S, F).crc64ISOOf); // [21, 185, 116, 95, 219, 11, 54, 7]
- alias
crcHexString
=crcHexString
;
aliascrcHexString
= std.digest.toHexString!(Order.decreasing, 16LU, LetterCase.upper).toHexString; - 通常のCRC32文字列出力を生成する。
- alias
CRC32Digest
= std.digest.WrapperDigest!(CRC!(32u, 3988292384LU)).WrapperDigest; - OOP API CRC32実装。 テンプレートと OOP API の違いについてはstd.digest を参照のこと。これは std.digest.WrapperDigest!CRC32のエイリアスである。 を参照のこと。
- alias
CRC64ECMADigest
= std.digest.WrapperDigest!(CRC!(64u, 14514072000185962306LU)).WrapperDigest; - OOP API CRC64-ECMA 実装。 テンプレートと OOP API の違いについてはstd.digest を参照のこと。これは std.digest.WrapperDigest!CRC64ECMA, の別名である。
- alias
CRC64ISODigest
= std.digest.WrapperDigest!(CRC!(64u, 15564440312192434176LU)).WrapperDigest; - OOP API CRC64-ISOの実装。 テンプレートとOOP APIの違いについてはstd.digest を参照のこと。これは std.digest.WrapperDigest!CRC64ISO, の別名である。Examples:
//単純な例として、CRC32Digest.digestヘルパー関数を使用して文字列をハッシュする auto crc = new CRC32Digest(); ubyte[] hash = crc.digest("abc"); //ハッシュ文字列を取得してみよう writeln(crcHexString(hash)); // "352441C2"
Examples://OOPの機能を使ってみよう: void test(Digest dig) { dig.put(cast(ubyte) 0); } auto crc = new CRC32Digest(); test(crc); //カスタム・バッファを使おう: ubyte[4] buf; ubyte[] result = crc.finish(buf[]); writeln(crcHexString(result)); // "D202EF8D"
Examples://簡単な例 auto hash = new CRC32Digest(); hash.put(cast(ubyte) 0); ubyte[] result = hash.finish();
Examples://供給されたバッファを使用する ubyte[4] buf; auto hash = new CRC32Digest(); hash.put(cast(ubyte) 0); ubyte[] result = hash.finish(buf[]); //結果がresultに入る(bufにも入る。必要以上に大きなバッファを渡すと、 //resultは正しい長さになるが、bufは元の長さの //ままである)
Copyright © 1999-2024 by the D Language Foundation
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.108.0
ドキュメントのdmdのバージョン: 2.109.1
翻訳日付 :
HTML生成日時:
編集者: dokutoku