hash tableとは? わかりやすく解説

Weblio 辞書 > 辞書・百科事典 > デジタル大辞泉 > hash tableの意味・解説 

ハッシュ‐テーブル【hash table】

読み方:はっしゅてーぶる

元の数値文字列ハッシュ関数によって得られハッシュ値を、一意的に結びつけて格納したデータ構造データ規模が特に大きな場合個々要素ハッシュ値結びつけることで、検索挿入削除などを高速化することができる。ハッシュ表


ハッシュ‐ひょう〔‐ヘウ〕【ハッシュ表】

読み方:はっしゅひょう

《hash table》⇒ハッシュテーブル


Hashtable クラス

キーハッシュ コード基づいて編成された、キー/値ペアコレクション表します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class Hashtable
    Implements IDictionary, ICollection, IEnumerable, ISerializable,
 _
    IDeserializationCallback, ICloneable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class Hashtable : IDictionary, ICollection,
 IEnumerable, 
    ISerializable, IDeserializationCallback, ICloneable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class Hashtable : IDictionary, ICollection,
 IEnumerable, 
    ISerializable, IDeserializationCallback, ICloneable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Hashtable implements IDictionary,
 ICollection, 
    IEnumerable, ISerializable, IDeserializationCallback, ICloneable
SerializableAttribute 
ComVisibleAttribute(true) 
public class Hashtable implements IDictionary,
 ICollection, 
    IEnumerable, ISerializable, IDeserializationCallback, ICloneable
解説解説

各要素は、DictionaryEntry オブジェクト格納されているキー/値ペアです。キーには null 参照 (Visual Basic では Nothing) は使用できませんが、値は null でもかまいません

Hashtableキーとして使用されるオブジェクトは、Object.GetHashCode メソッド (または IHashCodeProvider インターフェイス) および Object.Equals メソッド (または IComparer インターフェイス) をオーバーライドする必要がありますメソッドおよびインターフェイスのどちらの実装でも、大文字と小文字区別を同じ方法処理する必要がありますそのように実装されていないと、Hashtable正しく動作しない場合あります。たとえば、Hashtable作成するとき、CaseInsensitiveHashCodeProvider クラス (または大文字と小文字区別しない任意の IHashCodeProvider 実装) は、CaseInsensitiveComparer クラス (または大文字と小文字区別しない任意の IComparer 実装) と共に使用する必要があります

また、これらのメソッドは、キーHashtable存在している間に同じパラメータ指定して呼び出され場合は、同じ結果生成する必要があります代わりにHashtable コンストラクタで IEqualityComparer パラメータ使用することもできますキー等値単純に参照等値である場合は、Object.GetHashCode および Object.Equals継承して実装するだけで十分です。

キー オブジェクトは、Hashtableキーとして使用されている間は不変であることが必要です。

Hashtable要素追加されると、その要素キーハッシュ コード基づいてバケット配置されます。それ以後キー検索する際には、そのキーハッシュ コード使用して1 つバケットだけを検索します。これにより、要素を見つけるために必要となるキー比較回数を減らすことができます

Hashtableテーブル占有率は、バケット数に対す要素数の最大比率決定しますテーブル占有率小さくすると、検索時間平均的に短くなりますが、メモリ消費量増加します。既定テーブル占有率1.0 です。通常、この値は、検索速度サイズ最適なバランス実現しますHashtable作成するときに、既定値とは異なテーブル占有率指定することもできます

Hashtable要素追加されると、Hashtable実際テーブル占有率大きくなります実際テーブル占有率指定した占有率達すると、Hashtableバケット数は、現在の Hashtableバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

Hashtable の各キー オブジェクトは、GetHash を呼び出すことによってアクセスできる独自のハッシュ関数用意する必要があります。ただし、IHashCodeProvider実装するオブジェクトHashtable コンストラクタに渡すことができ、そのハッシュ関数テーブル内のすべてのオブジェクトに対して使用できます

Hashtable容量は、Hashtable保持できる要素数になりますHashtable既定初期量はゼロです。Hashtable要素追加すると、必要に応じて、再割り当てを行うことによって容量自動的に増加します。

C# 言語foreach ステートメント (Visual Basic では for each) は、コレクション内の各要素の型を必要としますHashtable各要素キー/値ペアであるため、要素の型は、キーの型や値の型にはなりません。その代わり要素の型は DictionaryEntryなります。例 :

foreach (DictionaryEntry de in myHashtable)
 {...}
For Each de as DictionaryEntry
 In myHashtable
   ...
Next de

foreach ステートメントは、列挙子のラッパーです。これは、コレクションからの読み取りだけを許可しコレクションへの書き込み防ぎます

Hashtable列挙子をシリアル化または逆シリアル化すると要素順番変更される場合があるため、列挙続けるためには Reset メソッド呼び出す必要があります

使用例使用例

Hashtable作成および初期化し、それに対して各種関数実行する方法と、そのキーと値を出力する方法の例を次に示します

Imports System
Imports System.Collections

Module Example

    Sub Main()

        ' Create a new hash table.
        '
        Dim openWith As New
 Hashtable()

        ' Add some elements to the hash table. There are no 
        ' duplicate keys, but some of the values are duplicates.
        openWith.Add("txt", "notepad.exe")
        openWith.Add("bmp", "paint.exe")
        openWith.Add("dib", "paint.exe")
        openWith.Add("rtf", "wordpad.exe")

        ' The Add method throws an exception if the new key is 
        ' already in the hash table.
        Try
            openWith.Add("txt", "winword.exe")
        Catch
            Console.WriteLine("An element with Key = ""txt""
 already exists.")
        End Try

        ' The Item property is the default property, so you 
        ' can omit its name when accessing elements. 
        Console.WriteLine("For key = ""rtf"",
 value = {0}.", _
            openWith("rtf"))

        ' The default Item property can be used to change the value
        ' associated with a key.
        openWith("rtf") = "winword.exe"
        Console.WriteLine("For key = ""rtf"",
 value = {0}.", _
            openWith("rtf"))

        ' If a key does not exist, setting the default Item property
        ' for that key adds a new key/value pair.
        openWith("doc") = "winword.exe"

        ' The default Item property throws an exception if the requested
        ' key is not in the hash table.
        Try
            Console.WriteLine("For key = ""tif"",
 value = {0}.", _
                openWith("tif"))
        Catch
            Console.WriteLine("Key = ""tif""
 is not found.")
        End Try

        ' ContainsKey can be used to test keys before inserting 
        ' them.
        If Not openWith.ContainsKey("ht")
 Then
            openWith.Add("ht", "hypertrm.exe")
            Console.WriteLine("Value added for key = ""ht"":
 {0}", _
                openWith("ht"))
        End If

        ' When you use foreach to enumerate hash table elements,
        ' the elements are retrieved as KeyValuePair objects.
        Console.WriteLine()
        For Each de As DictionaryEntry
 In openWith
            Console.WriteLine("Key = {0}, Value = {1}",
 _
                de.Key, de.Value)
        Next de

        ' To get the values alone, use the Values property.
        Dim valueColl As ICollection = openWith.Values

        ' The elements of the ValueCollection are strongly typed
        ' with the type that was specified for hash table values.
        Console.WriteLine()
        For Each s As String
 In valueColl
            Console.WriteLine("Value = {0}", s)
        Next s

        ' To get the keys alone, use the Keys property.
        Dim keyColl As ICollection = openWith.Keys

        ' The elements of the KeyCollection are strongly typed
        ' with the type that was specified for hash table keys.
        Console.WriteLine()
        For Each s As String
 In keyColl
            Console.WriteLine("Key = {0}", s)
        Next s

        ' Use the Remove method to remove a key/value pair.
        Console.WriteLine(vbLf + "Remove(""doc"")")
        openWith.Remove("doc")

        If Not openWith.ContainsKey("doc")
 Then
            Console.WriteLine("Key ""doc""
 is not found.")
        End If

    End Sub

End Module

' This code example produces the following output:
'
'An element with Key = "txt" already exists.
'For key = "rtf", value = wordpad.exe.
'For key = "rtf", value = winword.exe.
'For key = "tif", value = .
'Value added for key = "ht": hypertrm.exe
'
'Key = dib, Value = paint.exe
'Key = txt, Value = notepad.exe
'Key = ht, Value = hypertrm.exe
'Key = bmp, Value = paint.exe
'Key = rtf, Value = winword.exe
'Key = doc, Value = winword.exe
'
'Value = paint.exe
'Value = notepad.exe
'Value = hypertrm.exe
'Value = paint.exe
'Value = winword.exe
'Value = winword.exe
'
'Key = dib
'Key = txt
'Key = ht
'Key = bmp
'Key = rtf
'Key = doc
'
'Remove("doc")
'Key "doc" is not found.
using System;
using System.Collections;

class Example
{
    public static void Main()
    {
        // Create a new hash table.
        //
        Hashtable openWith = new Hashtable();
        
        // Add some elements to the hash table. There are no 
        // duplicate keys, but some of the values are duplicates.
        openWith.Add("txt", "notepad.exe");
        openWith.Add("bmp", "paint.exe");
        openWith.Add("dib", "paint.exe");
        openWith.Add("rtf", "wordpad.exe");
        
        // The Add method throws an exception if the new key is 
        // already in the hash table.
        try
        {
            openWith.Add("txt", "winword.exe");
        }
        catch
        {
            Console.WriteLine("An element with Key = \"txt\" already
 exists.");
        }

        // The Item property is the default property, so you 
        // can omit its name when accessing elements. 
        Console.WriteLine("For key = \"rtf\", value = {0}.",
 openWith["rtf"]);
        
        // The default Item property can be used to change the value
        // associated with a key.
        openWith["rtf"] = "winword.exe";
        Console.WriteLine("For key = \"rtf\", value = {0}.",
 openWith["rtf"]);
        
        // If a key does not exist, setting the default Item property
        // for that key adds a new key/value pair.
        openWith["doc"] = "winword.exe";

        // The default Item property throws an exception if the requested
        // key is not in the hash table.
        try
        {
            Console.WriteLine("For key = \"tif\", value = {0}.",
 openWith["tif"]);
        }
        catch
        {
            Console.WriteLine("Key = \"tif\" is not found.");
        }

        // ContainsKey can be used to test keys before inserting 
        // them.
        if (!openWith.ContainsKey("ht"))
        {
            openWith.Add("ht", "hypertrm.exe");
            Console.WriteLine("Value added for key = \"ht\":
 {0}", openWith["ht"]);
        }

        // When you use foreach to enumerate hash table elements,
        // the elements are retrieved as KeyValuePair objects.
        Console.WriteLine();
        foreach( DictionaryEntry de in openWith
 )
        {
            Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
        }

        // To get the values alone, use the Values property.
        ICollection valueColl = openWith.Values;
        
        // The elements of the ValueCollection are strongly typed
        // with the type that was specified for hash table values.
        Console.WriteLine();
        foreach( string s in
 valueColl )
        {
            Console.WriteLine("Value = {0}", s);
        }

        // To get the keys alone, use the Keys property.
        ICollection keyColl = openWith.Keys;
        
        // The elements of the KeyCollection are strongly typed
        // with the type that was specified for hash table keys.
        Console.WriteLine();
        foreach( string s in
 keyColl )
        {
            Console.WriteLine("Key = {0}", s);
        }

        // Use the Remove method to remove a key/value pair.
        Console.WriteLine("\nRemove(\"doc\")");
        openWith.Remove("doc");
        
        if (!openWith.ContainsKey("doc"))
        {
            Console.WriteLine("Key \"doc\" is not found.");
        }
    }
}

/* This code example produces the following output:

An element with Key = "txt" already exists.
For key = "rtf", value = wordpad.exe.
For key = "rtf", value = winword.exe.
For key = "tif", value = .
Value added for key = "ht": hypertrm.exe

Key = dib, Value = paint.exe
Key = txt, Value = notepad.exe
Key = ht, Value = hypertrm.exe
Key = bmp, Value = paint.exe
Key = rtf, Value = winword.exe
Key = doc, Value = winword.exe

Value = paint.exe
Value = notepad.exe
Value = hypertrm.exe
Value = paint.exe
Value = winword.exe
Value = winword.exe

Key = dib
Key = txt
Key = ht
Key = bmp
Key = rtf
Key = doc

Remove("doc")
Key "doc" is not found.
 */
継承階層継承階層
System.Object
  System.Collections.Hashtable
     System.Configuration.SettingsAttributeDictionary
     System.Configuration.SettingsContext
     System.Data.PropertyCollection
スレッド セーフスレッド セーフ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable メンバ
System.Collections 名前空間
IDictionary
IHashCodeProvider
Object.GetHashCode
Object.Equals
DictionaryEntry 構造体
System.Collections.Generic.Dictionary
IEqualityComparer

Hashtable コンストラクタ ()

既定初期量、テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用して、Hashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説
使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myComparer
    Implements IEqualityComparer
    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        Return x.Equals(y)
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode

        Return obj.ToString().ToLower().GetHashCode()
    End Function

End Class

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New
 Hashtable()
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer
 that uses
        ' the default Object.Equals to determine equality.
        Dim myHT2 As New
 Hashtable(New myComparer())
        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using a case-insensitive hash code provider
 and
        ' case-insensitive comparer based on the InvariantCulture.
        Dim myHT3 As New
 Hashtable( _
            CaseInsensitiveHashCodeProvider.DefaultInvariant, _
            CaseInsensitiveComparer.DefaultInvariant)
        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based
 on
        ' the Turkish culture (tr-TR) where "I" is not the
 uppercase
        ' version of "i".
        Dim myCul As New
 CultureInfo("tr-TR")
        Dim myHT4 As New
 Hashtable(New myCultureComparer(myCul))
        myHT4.Add("FIRST", "Hello")
        myHT4.Add("SECOND", "World")
        myHT4.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))
        Console.WriteLine("first is in myHT4: {0}",
 myHT4.ContainsKey("first"))

    End Sub

End Class

'This code produces the following output.
'Results vary depending on the system's culture settings.

'first is in myHT1: False
'first is in myHT2: False
'first is in myHT3: True
'first is in myHT4: False
using System;
using System.Collections;
using System.Globalization;

class myComparer : IEqualityComparer
{
    public new bool Equals(object
 x, object y)
    {
        return x.Equals(y);
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable();
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the default Object.Equals to determine equality.
        Hashtable myHT2 = new Hashtable(new
 myComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using a case-insensitive hash code provider
 and
        // case-insensitive comparer based on the InvariantCulture.
        Hashtable myHT3 = new Hashtable(
            CaseInsensitiveHashCodeProvider.DefaultInvariant,
            CaseInsensitiveComparer.DefaultInvariant);
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT4 = new Hashtable(new
 myCultureComparer(myCul));
        myHT4.Add("FIRST", "Hello");
        myHT4.Add("SECOND", "World");
        myHT4.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));
        Console.WriteLine("first is in myHT4: {0}",
 myHT4.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myComparer : IEqualityComparer
{
public:
    virtual bool Equals(Object^ x, Object^ y) 
    {
        return x->Equals(y);
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

ref class myCultureComparer : IEqualityComparer
{
private:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

    virtual bool Equals(Object^ x, Object^ y) 
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

int main()
{
   
   // Create a hash table using the default hash code provider and the
 default comparer.
   Hashtable^ myHT1 = gcnew Hashtable((IEqualityComparer^)nullptr);
   myHT1->Add( "FIRST", "Hello" );
   myHT1->Add( "SECOND", "World" );
   myHT1->Add( "THIRD", "!" );
   
   // Create a hash table using the specified IEqualityComparer that
 uses
   // the default Object.Equals to determine equality.
   Hashtable^ myHT2 = gcnew Hashtable(gcnew myComparer());
   myHT2->Add( "FIRST", "Hello" );
   myHT2->Add( "SECOND", "World" );
   myHT2->Add( "THIRD", "!" );
   
   // Create a hash table using a case-insensitive hash code provider
 and
   // case-insensitive comparer based on the InvariantCulture.
   Hashtable^ myHT3 = gcnew Hashtable(
            CaseInsensitiveHashCodeProvider::DefaultInvariant,
            CaseInsensitiveComparer::DefaultInvariant);
   myHT3->Add( "FIRST", "Hello" );
   myHT3->Add( "SECOND", "World" );
   myHT3->Add( "THIRD", "!" );
   
   // Create a hash table using an IEqualityComparer that is based on
   // the Turkish culture (tr-TR) where "I" is not the uppercase
   // version of "i".
   CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
   Hashtable^ myHT4 = gcnew Hashtable( gcnew myCultureComparer(myCul) );
   myHT4->Add( "FIRST", "Hello" );
   myHT4->Add( "SECOND", "World" );
   myHT4->Add( "THIRD", "!" );
   
   // Search for a key in each hash table.
   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey(
 "first" ) );
}

/* 
This code produces the following output.  Results vary depending on the system's
 culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (Int32, Single)

指定した初期量とテーブル占有率、および既定ハッシュ コード プロバイダ比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

または

loadFactor0.1 未満です。

または

loadFactor1.0 より大きい値です。

解説解説
使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New
 Hashtable(3, System.Convert.ToSingle(0.8))
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer
 that uses
        ' the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Dim myHT2 As New
 Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer())

        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based
 on
        ' the Turkish culture (tr-TR) where "I" is not the
 uppercase
        ' version of "i".
        Dim myCul As New
 CultureInfo("tr-TR")
        Dim myHT3 As New
 Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer(myCul))

        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

    End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3, (float).8);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(3, (float).8,
 new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, (float).8,
 
            new myCultureComparer(myCul));

        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (IDictionary, IHashCodeProvider, IComparer)

メモ : このコンストラクタは、互換性のために残されています。

指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、既定テーブル占有率、および指定したハッシュ コード プロバイダ比較演算子使用します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ObsoleteAttribute("Please use Hashtable(IDictionary, IEqualityComparer)
 instead.")> _
Public Sub New ( _
    d As IDictionary, _
    hcp As IHashCodeProvider, _
    comparer As IComparer _
)
Dim d As IDictionary
Dim hcp As IHashCodeProvider
Dim comparer As IComparer

Dim instance As New Hashtable(d,
 hcp, comparer)
[ObsoleteAttribute("Please use Hashtable(IDictionary, IEqualityComparer) instead.")]
 
public Hashtable (
    IDictionary d,
    IHashCodeProvider hcp,
    IComparer comparer
)
[ObsoleteAttribute(L"Please use Hashtable(IDictionary, IEqualityComparer) instead.")]
 
public:
Hashtable (
    IDictionary^ d, 
    IHashCodeProvider^ hcp, 
    IComparer^ comparer
)
/** @attribute ObsoleteAttribute("Please use Hashtable(IDictionary, IEqualityComparer)
 instead.") */ 
public Hashtable (
    IDictionary d, 
    IHashCodeProvider hcp, 
    IComparer comparer
)
ObsoleteAttribute("Please use Hashtable(IDictionary, IEqualityComparer) instead.")
 
public function Hashtable (
    d : IDictionary, 
    hcp : IHashCodeProvider, 
    comparer : IComparer
)

パラメータ

d

新しい Hashtable オブジェクトコピーする IDictionary オブジェクト

hcp

Hashtable 内のすべてのキーハッシュ コード提供する IHashCodeProvider オブジェクト

または

キーの Object.GetHashCode の実装である既定ハッシュ コード プロバイダ使用する場合null 参照 (Visual Basic では Nothing)。

comparer

2 つキー等しかどうか判断するために使用する IComparer オブジェクト

または

キーの Object.Equals の実装である既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

解説解説

初期量は、コピー元のディクショナリ内の要素数に設定されます。容量は、必要に応じてテーブル占有率基づいて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

ハッシュ コード プロバイダは、Hashtable オブジェクト内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

カスタム ハッシュ コード プロバイダカスタム比較演算子使用すると、大文字と小文字区別しない文字列検索などの処理を実行できます

新しHashtable要素は、列挙子が IDictionary オブジェクト反復処理するのと同じ順序並べ替えられます。

このコンストラクタは O(n) 操作です。ここで、nd パラメータ内の要素数です。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL)

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL,
 New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL,
 New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(mySL, new
 myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, new
 myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
    static void Main()
    {
        // Create the dictionary.
        SortedList^ mySL = gcnew SortedList();
        mySL->Add("FIRST", "Hello");
        mySL->Add("SECOND", "World");
        mySL->Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable^ myHT2 = gcnew Hashtable(mySL, gcnew myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(mySL, gcnew myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console::WriteLine("first is in myHT1: {0}",
 myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}",
 myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}",
 myHT3->ContainsKey("first"));
    }
};

int main()
{
    SamplesHashtable::Main();
};

/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
IDictionary
IHashCodeProvider
IComparer
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (IDictionary, Single, IEqualityComparer)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、指定したテーブル占有率および IEqualityComparer オブジェクト使用します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    d As IDictionary, _
    loadFactor As Single, _
    equalityComparer As IEqualityComparer _
)
Dim d As IDictionary
Dim loadFactor As Single
Dim equalityComparer As IEqualityComparer

Dim instance As New Hashtable(d,
 loadFactor, equalityComparer)
public Hashtable (
    IDictionary d,
    float loadFactor,
    IEqualityComparer equalityComparer
)
public:
Hashtable (
    IDictionary^ d, 
    float loadFactor, 
    IEqualityComparer^ equalityComparer
)
public Hashtable (
    IDictionary d, 
    float loadFactor, 
    IEqualityComparer equalityComparer
)
public function Hashtable (
    d : IDictionary, 
    loadFactor : float, 
    equalityComparer : IEqualityComparer
)

パラメータ

d

新しい Hashtable オブジェクトコピーする IDictionary オブジェクト

loadFactor

0.11.0範囲の値。これに、最高のパフォーマンス提供する既定値掛けますその結果が、バケット数に対す要素数の最大比率です。

equalityComparer

Hashtable使用するハッシュ コード プロバイダ比較演算子定義する IEqualityComparer オブジェクト

または

既定ハッシュ コード プロバイダおよび既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。既定ハッシュ コード プロバイダは、各キーの Object.GetHashCode の実装です。また、既定比較演算子は各キーの Object.Equals の実装です。

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

loadFactor0.1 未満です。

または

loadFactor1.0 より大きい値です。

解説解説

初期量は、コピー元のディクショナリ内の要素数に設定されます。容量は、必要に応じてテーブル占有率基づいて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。テーブル占有率 1.0 は、検索速度サイズ最適なバランス実現します

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

IEqualityComparer オブジェクトには、ハッシュ コード プロバイダおよび比較演算子含まれます。IEqualityComparerHashtable コンストラクタ使用される場合Hashtable オブジェクトキーとして使用されるオブジェクトは、Object.GetHashCode メソッドおよび Object.Equals メソッドオーバーライドする必要はありません。

ハッシュ コード プロバイダは、Hashtable 内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

IEqualityComparer により、大文字と小文字区別せずに文字列の検索を行うようなシナリオ可能になります

新しHashtable要素は、列挙子が IDictionary オブジェクト反復処理するのと同じ順序並べ替えられます。

このコンストラクタは O(n) 操作です。ここで、nd パラメータ内の要素数です。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8))

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8), _
        New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8), _
        New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL, (float).8);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(mySL, (float).8,
 
            new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, (float).8,
 
            new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Hashtable コンストラクタ (Int32, Single, IEqualityComparer)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定した初期量、テーブル占有率、および IEqualityComparer オブジェクト使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    capacity As Integer, _
    loadFactor As Single, _
    equalityComparer As IEqualityComparer _
)
Dim capacity As Integer
Dim loadFactor As Single
Dim equalityComparer As IEqualityComparer

Dim instance As New Hashtable(capacity,
 loadFactor, equalityComparer)
public Hashtable (
    int capacity,
    float loadFactor,
    IEqualityComparer equalityComparer
)
public:
Hashtable (
    int capacity, 
    float loadFactor, 
    IEqualityComparer^ equalityComparer
)
public Hashtable (
    int capacity, 
    float loadFactor, 
    IEqualityComparer equalityComparer
)
public function Hashtable (
    capacity : int, 
    loadFactor : float, 
    equalityComparer : IEqualityComparer
)

パラメータ

capacity

Hashtable オブジェクト初期状態格納できる要素概数

loadFactor

0.11.0範囲の値。これに、最高のパフォーマンス提供する既定値掛けますその結果が、バケット数に対す要素数の最大比率です。

equalityComparer

Hashtable使用するハッシュ コード プロバイダ比較演算子定義する IEqualityComparer オブジェクト

または

既定ハッシュ コード プロバイダおよび既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。既定ハッシュ コード プロバイダは、各キーの Object.GetHashCode の実装です。また、既定比較演算子は各キーの Object.Equals の実装です。

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

または

loadFactor0.1 未満です。

または

loadFactor1.0 より大きい値です。

解説解説

初期量を指定すると、Hashtable オブジェクト要素追加するときに、サイズ変更操作何度も実行する必要がなくなります容量は、必要に応じてテーブル占有率基づいて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。テーブル占有率 1.0 は、検索速度サイズ最適なバランス実現します

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

IEqualityComparer オブジェクトには、ハッシュ コード プロバイダおよび比較演算子含まれます。IEqualityComparerHashtable コンストラクタ使用される場合Hashtableキーとして使用されるオブジェクトは、Object.GetHashCode メソッドおよび Object.Equals メソッドオーバーライドする必要はありません。

ハッシュ コード プロバイダは、Hashtable 内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

IEqualityComparer により、大文字と小文字区別せずに文字列の検索を行うようなシナリオ可能になります

このコンストラクタは O(n) 操作です。ここで、ncapacity パラメータです。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New
 Hashtable(3, System.Convert.ToSingle(0.8))
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer
 that uses
        ' the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Dim myHT2 As New
 Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer())

        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based
 on
        ' the Turkish culture (tr-TR) where "I" is not the
 uppercase
        ' version of "i".
        Dim myCul As New
 CultureInfo("tr-TR")
        Dim myHT3 As New
 Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer(myCul))

        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

    End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3, (float).8);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(3, (float).8,
 new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, (float).8,
 
            new myCultureComparer(myCul));

        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Hashtable コンストラクタ (IDictionary, Single, IHashCodeProvider, IComparer)

メモ : このコンストラクタは、互換性のために残されています。

指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、指定したテーブル占有率ハッシュ コード プロバイダ、および比較演算子使用します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ObsoleteAttribute("Please use Hashtable(IDictionary, float,
 IEqualityComparer) instead.")> _
Public Sub New ( _
    d As IDictionary, _
    loadFactor As Single, _
    hcp As IHashCodeProvider, _
    comparer As IComparer _
)
Dim d As IDictionary
Dim loadFactor As Single
Dim hcp As IHashCodeProvider
Dim comparer As IComparer

Dim instance As New Hashtable(d,
 loadFactor, hcp, comparer)
[ObsoleteAttribute("Please use Hashtable(IDictionary, float,
 IEqualityComparer) instead.")] 
public Hashtable (
    IDictionary d,
    float loadFactor,
    IHashCodeProvider hcp,
    IComparer comparer
)
[ObsoleteAttribute(L"Please use Hashtable(IDictionary, float,
 IEqualityComparer) instead.")] 
public:
Hashtable (
    IDictionary^ d, 
    float loadFactor, 
    IHashCodeProvider^ hcp, 
    IComparer^ comparer
)
/** @attribute ObsoleteAttribute("Please use Hashtable(IDictionary, float,
 IEqualityComparer) instead.") */ 
public Hashtable (
    IDictionary d, 
    float loadFactor, 
    IHashCodeProvider hcp, 
    IComparer comparer
)
ObsoleteAttribute("Please use Hashtable(IDictionary, float,
 IEqualityComparer) instead.") 
public function Hashtable (
    d : IDictionary, 
    loadFactor : float, 
    hcp : IHashCodeProvider, 
    comparer : IComparer
)

パラメータ

d

新しい Hashtable オブジェクトコピーする IDictionary オブジェクト

loadFactor

0.11.0範囲の値。これに、最高のパフォーマンス提供する既定値掛けますその結果が、バケット数に対す要素数の最大比率です。

hcp

Hashtable 内のすべてのキーハッシュ コード提供する IHashCodeProvider オブジェクト

または

キーの Object.GetHashCode の実装である既定ハッシュ コード プロバイダ使用する場合null 参照 (Visual Basic では Nothing)。

comparer

2 つキー等しかどうか判断するために使用する IComparer オブジェクト

または

キーの Object.Equals の実装である既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

loadFactor0.1 未満です。

または

loadFactor1.0 より大きい値です。

解説解説

初期量は、コピー元のディクショナリ内の要素数に設定されます。容量は、必要に応じてテーブル占有率基づいて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。テーブル占有率 1.0 は、検索速度サイズ最適なバランス実現します

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

ハッシュ コード プロバイダは、Hashtable オブジェクト内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

カスタム ハッシュ コード プロバイダカスタム比較演算子使用すると、大文字と小文字区別しない文字列検索などの処理を実行できます

新しHashtable要素は、列挙子が IDictionary オブジェクト反復処理するのと同じ順序並べ替えられます。

このコンストラクタは O(n) 操作です。ここで、nd パラメータ内の要素数です。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8))

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8), _
        New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8), _
        New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL, (float).8);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(mySL, (float).8,
 
            new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, (float).8,
 
            new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Hashtable コンストラクタ

Hashtable クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
Hashtable () 既定初期量、テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (IDictionary) 指定したディレクトリ要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、既定テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用します

.NET Compact Framework によってサポートされています。

Hashtable (IEqualityComparer) 既定初期量とテーブル占有率、および指定した IEqualityComparer オブジェクト使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (Int32) 指定した初期量と、既定テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (IDictionary, IEqualityComparer) 指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、既定テーブル占有率および指定した IEqualityComparer オブジェクト使用します

.NET Compact Framework によってサポートされています。

Hashtable (IDictionary, Single) 指定したディレクトリ要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、指定したテーブル占有率、および既定ハッシュ コード プロバイダ比較演算子使用します

.NET Compact Framework によってサポートされています。

Hashtable (IHashCodeProvider, IComparer) 既定初期量とテーブル占有率、および指定したハッシュ コード プロバイダ比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (Int32, IEqualityComparer) 指定した初期量と IEqualityComparer、および既定テーブル占有率使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (Int32, Single) 指定した初期量とテーブル占有率、および既定ハッシュ コード プロバイダ比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (SerializationInfo, StreamingContext) 指定した SerializationInfo オブジェクトと StreamingContext オブジェクト使用してシリアル化できる、Hashtable クラス新しい空のインスタンス初期化します。
Hashtable (IDictionary, IHashCodeProvider, IComparer) 指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、既定テーブル占有率、および指定したハッシュ コード プロバイダ比較演算子使用します

.NET Compact Framework によってサポートされています。

Hashtable (IDictionary, Single, IEqualityComparer) 指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、指定したテーブル占有率および IEqualityComparer オブジェクト使用します

.NET Compact Framework によってサポートされています。

Hashtable (Int32, IHashCodeProvider, IComparer) 指定した初期量、ハッシュ コード プロバイダ、および比較演算子と、既定テーブル占有率使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (Int32, Single, IEqualityComparer) 指定した初期量、テーブル占有率、および IEqualityComparer オブジェクト使用してHashtable クラス新しい空のインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Hashtable (IDictionary, Single, IHashCodeProvider, IComparer) 指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、指定したテーブル占有率ハッシュ コード プロバイダ、および比較演算子使用します
Hashtable (Int32, Single, IHashCodeProvider, IComparer) 指定した初期量、テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。
参照参照

関連項目

Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (IDictionary, Single)

指定したディレクトリ要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、指定したテーブル占有率、および既定ハッシュ コード プロバイダ比較演算子使用します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    d As IDictionary, _
    loadFactor As Single _
)
Dim d As IDictionary
Dim loadFactor As Single

Dim instance As New Hashtable(d,
 loadFactor)
public Hashtable (
    IDictionary d,
    float loadFactor
)
public:
Hashtable (
    IDictionary^ d, 
    float loadFactor
)
public Hashtable (
    IDictionary d, 
    float loadFactor
)
public function Hashtable (
    d : IDictionary, 
    loadFactor : float
)

パラメータ

d

新しい Hashtable オブジェクトコピーする IDictionary オブジェクト

loadFactor

0.11.0範囲の値。これに、最高のパフォーマンス提供する既定値掛けますその結果が、バケット数に対す要素数の最大比率です。

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

loadFactor0.1 未満です。

または

loadFactor1.0 より大きい値です。

解説解説
使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8))

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8), _
        New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL,
 System.Convert.ToSingle(0.8), _
        New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL, (float).8);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(mySL, (float).8,
 
            new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, (float).8,
 
            new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
IDictionary
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (Int32, IHashCodeProvider, IComparer)

メモ : このコンストラクタは、互換性のために残されています。

指定した初期量、ハッシュ コード プロバイダ、および比較演算子と、既定テーブル占有率使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ObsoleteAttribute("Please use Hashtable(int, IEqualityComparer)
 instead.")> _
Public Sub New ( _
    capacity As Integer, _
    hcp As IHashCodeProvider, _
    comparer As IComparer _
)
Dim capacity As Integer
Dim hcp As IHashCodeProvider
Dim comparer As IComparer

Dim instance As New Hashtable(capacity,
 hcp, comparer)
[ObsoleteAttribute("Please use Hashtable(int, IEqualityComparer)
 instead.")] 
public Hashtable (
    int capacity,
    IHashCodeProvider hcp,
    IComparer comparer
)
[ObsoleteAttribute(L"Please use Hashtable(int, IEqualityComparer)
 instead.")] 
public:
Hashtable (
    int capacity, 
    IHashCodeProvider^ hcp, 
    IComparer^ comparer
)
/** @attribute ObsoleteAttribute("Please use Hashtable(int,
 IEqualityComparer) instead.") */ 
public Hashtable (
    int capacity, 
    IHashCodeProvider hcp, 
    IComparer comparer
)
ObsoleteAttribute("Please use Hashtable(int, IEqualityComparer)
 instead.") 
public function Hashtable (
    capacity : int, 
    hcp : IHashCodeProvider, 
    comparer : IComparer
)

パラメータ

capacity

Hashtable オブジェクト初期状態格納できる要素概数

hcp

Hashtable 内のすべてのキーハッシュ コード提供する IHashCodeProvider オブジェクト

または

キーの Object.GetHashCode の実装である既定ハッシュ コード プロバイダ使用する場合null 参照 (Visual Basic では Nothing)。

comparer

2 つキー等しかどうか判断するために使用する IComparer オブジェクト

または

キーの Object.Equals の実装である既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説
使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(3)
      myHT1.Add("FIRST", "Hello")
      myHT1.Add("SECOND", "World")
      myHT1.Add("THIRD", "!")

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(3,
 New myCultureComparer())
      myHT2.Add("FIRST", "Hello")
      myHT2.Add("SECOND", "World")
      myHT2.Add("THIRD", "!")

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(3,
 New myCultureComparer(myCul))
      myHT3.Add("FIRST", "Hello")
      myHT3.Add("SECOND", "World")
      myHT3.Add("THIRD", "!")

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(3, new
 myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, new
 myCultureComparer(myCul));
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
IHashCodeProvider
IComparer
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (IHashCodeProvider, IComparer)

メモ : このコンストラクタは、互換性のために残されています。

既定初期量とテーブル占有率、および指定したハッシュ コード プロバイダ比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ObsoleteAttribute("Please use Hashtable(IEqualityComparer)
 instead.")> _
Public Sub New ( _
    hcp As IHashCodeProvider, _
    comparer As IComparer _
)
Dim hcp As IHashCodeProvider
Dim comparer As IComparer

Dim instance As New Hashtable(hcp,
 comparer)
[ObsoleteAttribute("Please use Hashtable(IEqualityComparer) instead.")]
 
public Hashtable (
    IHashCodeProvider hcp,
    IComparer comparer
)
[ObsoleteAttribute(L"Please use Hashtable(IEqualityComparer) instead.")]
 
public:
Hashtable (
    IHashCodeProvider^ hcp, 
    IComparer^ comparer
)
/** @attribute ObsoleteAttribute("Please use Hashtable(IEqualityComparer) instead.")
 */ 
public Hashtable (
    IHashCodeProvider hcp, 
    IComparer comparer
)
ObsoleteAttribute("Please use Hashtable(IEqualityComparer) instead.") 
public function Hashtable (
    hcp : IHashCodeProvider, 
    comparer : IComparer
)

パラメータ

hcp

Hashtable オブジェクト内のすべてのキーハッシュ コード提供する IHashCodeProvider オブジェクト

または

キーの Object.GetHashCode の実装である既定ハッシュ コード プロバイダ使用する場合null 参照 (Visual Basic では Nothing)。

comparer

2 つキー等しかどうか判断するために使用する IComparer オブジェクト

または

キーの Object.Equals の実装である既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。

解説解説
使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myComparer
    Implements IEqualityComparer
    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        Return x.Equals(y)
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode

        Return obj.ToString().ToLower().GetHashCode()
    End Function

End Class

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New
 Hashtable()
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer
 that uses
        ' the default Object.Equals to determine equality.
        Dim myHT2 As New
 Hashtable(New myComparer())
        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using a case-insensitive hash code provider
 and
        ' case-insensitive comparer based on the InvariantCulture.
        Dim myHT3 As New
 Hashtable( _
            CaseInsensitiveHashCodeProvider.DefaultInvariant, _
            CaseInsensitiveComparer.DefaultInvariant)
        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based
 on
        ' the Turkish culture (tr-TR) where "I" is not the
 uppercase
        ' version of "i".
        Dim myCul As New
 CultureInfo("tr-TR")
        Dim myHT4 As New
 Hashtable(New myCultureComparer(myCul))
        myHT4.Add("FIRST", "Hello")
        myHT4.Add("SECOND", "World")
        myHT4.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))
        Console.WriteLine("first is in myHT4: {0}",
 myHT4.ContainsKey("first"))

    End Sub

End Class

'This code produces the following output.
'Results vary depending on the system's culture settings.

'first is in myHT1: False
'first is in myHT2: False
'first is in myHT3: True
'first is in myHT4: False
using System;
using System.Collections;
using System.Globalization;

class myComparer : IEqualityComparer
{
    public new bool Equals(object
 x, object y)
    {
        return x.Equals(y);
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable();
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the default Object.Equals to determine equality.
        Hashtable myHT2 = new Hashtable(new
 myComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using a case-insensitive hash code provider
 and
        // case-insensitive comparer based on the InvariantCulture.
        Hashtable myHT3 = new Hashtable(
            CaseInsensitiveHashCodeProvider.DefaultInvariant,
            CaseInsensitiveComparer.DefaultInvariant);
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT4 = new Hashtable(new
 myCultureComparer(myCul));
        myHT4.Add("FIRST", "Hello");
        myHT4.Add("SECOND", "World");
        myHT4.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));
        Console.WriteLine("first is in myHT4: {0}",
 myHT4.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myComparer : IEqualityComparer
{
public:
    virtual bool Equals(Object^ x, Object^ y) 
    {
        return x->Equals(y);
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

ref class myCultureComparer : IEqualityComparer
{
private:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

    virtual bool Equals(Object^ x, Object^ y) 
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

int main()
{
   
   // Create a hash table using the default hash code provider and the
 default comparer.
   Hashtable^ myHT1 = gcnew Hashtable((IEqualityComparer^)nullptr);
   myHT1->Add( "FIRST", "Hello" );
   myHT1->Add( "SECOND", "World" );
   myHT1->Add( "THIRD", "!" );
   
   // Create a hash table using the specified IEqualityComparer that
 uses
   // the default Object.Equals to determine equality.
   Hashtable^ myHT2 = gcnew Hashtable(gcnew myComparer());
   myHT2->Add( "FIRST", "Hello" );
   myHT2->Add( "SECOND", "World" );
   myHT2->Add( "THIRD", "!" );
   
   // Create a hash table using a case-insensitive hash code provider
 and
   // case-insensitive comparer based on the InvariantCulture.
   Hashtable^ myHT3 = gcnew Hashtable(
            CaseInsensitiveHashCodeProvider::DefaultInvariant,
            CaseInsensitiveComparer::DefaultInvariant);
   myHT3->Add( "FIRST", "Hello" );
   myHT3->Add( "SECOND", "World" );
   myHT3->Add( "THIRD", "!" );
   
   // Create a hash table using an IEqualityComparer that is based on
   // the Turkish culture (tr-TR) where "I" is not the uppercase
   // version of "i".
   CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
   Hashtable^ myHT4 = gcnew Hashtable( gcnew myCultureComparer(myCul) );
   myHT4->Add( "FIRST", "Hello" );
   myHT4->Add( "SECOND", "World" );
   myHT4->Add( "THIRD", "!" );
   
   // Search for a key in each hash table.
   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey(
 "first" ) );
}

/* 
This code produces the following output.  Results vary depending on the system's
 culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
IHashCodeProvider
IComparer
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (Int32, Single, IHashCodeProvider, IComparer)

メモ : このコンストラクタは、互換性のために残されています。

指定した初期量、テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ObsoleteAttribute("Please use Hashtable(int, float, IEqualityComparer)
 instead.")> _
Public Sub New ( _
    capacity As Integer, _
    loadFactor As Single, _
    hcp As IHashCodeProvider, _
    comparer As IComparer _
)
Dim capacity As Integer
Dim loadFactor As Single
Dim hcp As IHashCodeProvider
Dim comparer As IComparer

Dim instance As New Hashtable(capacity,
 loadFactor, hcp, comparer)
[ObsoleteAttribute("Please use Hashtable(int, float,
 IEqualityComparer) instead.")] 
public Hashtable (
    int capacity,
    float loadFactor,
    IHashCodeProvider hcp,
    IComparer comparer
)
[ObsoleteAttribute(L"Please use Hashtable(int, float,
 IEqualityComparer) instead.")] 
public:
Hashtable (
    int capacity, 
    float loadFactor, 
    IHashCodeProvider^ hcp, 
    IComparer^ comparer
)
/** @attribute ObsoleteAttribute("Please use Hashtable(int,
 float, IEqualityComparer) instead.") */ 
public Hashtable (
    int capacity, 
    float loadFactor, 
    IHashCodeProvider hcp, 
    IComparer comparer
)
ObsoleteAttribute("Please use Hashtable(int, float,
 IEqualityComparer) instead.") 
public function Hashtable (
    capacity : int, 
    loadFactor : float, 
    hcp : IHashCodeProvider, 
    comparer : IComparer
)

パラメータ

capacity

Hashtable オブジェクト初期状態格納できる要素概数

loadFactor

0.11.0範囲の値。これに、最高のパフォーマンス提供する既定値掛けますその結果が、バケット数に対す要素数の最大比率です。

hcp

Hashtable 内のすべてのキーハッシュ コード提供する IHashCodeProvider オブジェクト

または

キーの Object.GetHashCode の実装である既定ハッシュ コード プロバイダ使用する場合null 参照 (Visual Basic では Nothing)。

comparer

2 つキー等しかどうか判断するために使用する IComparer オブジェクト

または

キーの Object.Equals の実装である既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

または

loadFactor0.1 未満です。

または

loadFactor1.0 より大きい値です。

解説解説

初期量を指定すると、Hashtable オブジェクト要素追加するときに、サイズ変更操作何度も実行する必要がなくなります容量は、必要に応じてテーブル占有率基づいて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。テーブル占有率 1.0 は、検索速度サイズ最適なバランス実現します

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

ハッシュ コード プロバイダは、Hashtable 内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

カスタム ハッシュ コード プロバイダカスタム比較演算子使用すると、大文字と小文字区別しない文字列検索などの処理を実行できます

このコンストラクタは O(n) 操作です。ここで、ncapacity パラメータです。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New
 Hashtable(3, System.Convert.ToSingle(0.8))
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer
 that uses
        ' the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Dim myHT2 As New
 Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer())

        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based
 on
        ' the Turkish culture (tr-TR) where "I" is not the
 uppercase
        ' version of "i".
        Dim myCul As New
 CultureInfo("tr-TR")
        Dim myHT3 As New
 Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer(myCul))

        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

    End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3, (float).8);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(3, (float).8,
 new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, (float).8,
 
            new myCultureComparer(myCul));

        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
IHashCodeProvider
IComparer
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (SerializationInfo, StreamingContext)

指定した SerializationInfo オブジェクトStreamingContext オブジェクト使用してシリアル化できる、Hashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New Hashtable(info,
 context)
protected Hashtable (
    SerializationInfo info,
    StreamingContext context
)
protected:
Hashtable (
    SerializationInfo^ info, 
    StreamingContext context
)
protected Hashtable (
    SerializationInfo info, 
    StreamingContext context
)
protected function Hashtable (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

Hashtable オブジェクトシリアル化するために必要な情報格納している SerializationInfo オブジェクト

context

Hashtable関連付けられているシリアル化ストリームソースおよびデスティネーション格納している StreamingContext オブジェクト

例外例外
例外種類条件

ArgumentNullException

infonull 参照 (Visual Basic では Nothing) です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
ISerializable
SerializationInfo
StreamingContext
OnDeserialization
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (Int32)

指定した初期量と、既定テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説
使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(3)
      myHT1.Add("FIRST", "Hello")
      myHT1.Add("SECOND", "World")
      myHT1.Add("THIRD", "!")

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(3,
 New myCultureComparer())
      myHT2.Add("FIRST", "Hello")
      myHT2.Add("SECOND", "World")
      myHT2.Add("THIRD", "!")

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(3,
 New myCultureComparer(myCul))
      myHT3.Add("FIRST", "Hello")
      myHT3.Add("SECOND", "World")
      myHT3.Add("THIRD", "!")

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(3, new
 myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, new
 myCultureComparer(myCul));
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (IDictionary)

指定したディレクトリ要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、既定テーブル占有率ハッシュ コード プロバイダ、および比較演算子使用します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    d As IDictionary _
)
Dim d As IDictionary

Dim instance As New Hashtable(d)
public Hashtable (
    IDictionary d
)
public:
Hashtable (
    IDictionary^ d
)
public Hashtable (
    IDictionary d
)
public function Hashtable (
    d : IDictionary
)

パラメータ

d

新しい Hashtable オブジェクトコピーする IDictionary オブジェクト

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL)

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL,
 New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL,
 New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(mySL, new
 myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, new
 myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
    static void Main()
    {
        // Create the dictionary.
        SortedList^ mySL = gcnew SortedList();
        mySL->Add("FIRST", "Hello");
        mySL->Add("SECOND", "World");
        mySL->Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable^ myHT2 = gcnew Hashtable(mySL, gcnew myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(mySL, gcnew myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console::WriteLine("first is in myHT1: {0}",
 myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}",
 myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}",
 myHT3->ContainsKey("first"));
    }
};

int main()
{
    SamplesHashtable::Main();
};

/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
IDictionary
Object.GetHashCode
Object.Equals

Hashtable コンストラクタ (IEqualityComparer)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

既定初期量とテーブル占有率、および指定した IEqualityComparer オブジェクト使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    equalityComparer As IEqualityComparer _
)
Dim equalityComparer As IEqualityComparer

Dim instance As New Hashtable(equalityComparer)
public Hashtable (
    IEqualityComparer equalityComparer
)
public:
Hashtable (
    IEqualityComparer^ equalityComparer
)
public Hashtable (
    IEqualityComparer equalityComparer
)
public function Hashtable (
    equalityComparer : IEqualityComparer
)

パラメータ

equalityComparer

Hashtable オブジェクト使用するハッシュ コード プロバイダ比較演算子定義する IEqualityComparer オブジェクト

または

既定ハッシュ コード プロバイダおよび既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。既定ハッシュ コード プロバイダは、各キーの Object.GetHashCode の実装です。また、既定比較演算子は各キーの Object.Equals の実装です。

解説解説

ハッシュ テーブル容量は、テーブル占有率基づいてハッシュ テーブル バケット最適数を計算するために使用されます。容量必要に応じて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

IEqualityComparer オブジェクトには、ハッシュ コード プロバイダおよび比較演算子含まれます。IEqualityComparerHashtable コンストラクタ使用される場合Hashtable オブジェクトキーとして使用されるオブジェクトは、Object.GetHashCode メソッドおよび Object.Equals メソッドオーバーライドする必要はありません。

ハッシュ コード プロバイダは、Hashtable 内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

IEqualityComparer により、大文字と小文字区別せずに文字列の検索を行うようなシナリオ可能になります

このコンストラクタは O(1) 操作です。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myComparer
    Implements IEqualityComparer
    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        Return x.Equals(y)
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode

        Return obj.ToString().ToLower().GetHashCode()
    End Function

End Class

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New
 Hashtable()
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer
 that uses
        ' the default Object.Equals to determine equality.
        Dim myHT2 As New
 Hashtable(New myComparer())
        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using a case-insensitive hash code provider
 and
        ' case-insensitive comparer based on the InvariantCulture.
        Dim myHT3 As New
 Hashtable( _
            CaseInsensitiveHashCodeProvider.DefaultInvariant, _
            CaseInsensitiveComparer.DefaultInvariant)
        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based
 on
        ' the Turkish culture (tr-TR) where "I" is not the
 uppercase
        ' version of "i".
        Dim myCul As New
 CultureInfo("tr-TR")
        Dim myHT4 As New
 Hashtable(New myCultureComparer(myCul))
        myHT4.Add("FIRST", "Hello")
        myHT4.Add("SECOND", "World")
        myHT4.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))
        Console.WriteLine("first is in myHT4: {0}",
 myHT4.ContainsKey("first"))

    End Sub

End Class

'This code produces the following output.
'Results vary depending on the system's culture settings.

'first is in myHT1: False
'first is in myHT2: False
'first is in myHT3: True
'first is in myHT4: False
using System;
using System.Collections;
using System.Globalization;

class myComparer : IEqualityComparer
{
    public new bool Equals(object
 x, object y)
    {
        return x.Equals(y);
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable();
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the default Object.Equals to determine equality.
        Hashtable myHT2 = new Hashtable(new
 myComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using a case-insensitive hash code provider
 and
        // case-insensitive comparer based on the InvariantCulture.
        Hashtable myHT3 = new Hashtable(
            CaseInsensitiveHashCodeProvider.DefaultInvariant,
            CaseInsensitiveComparer.DefaultInvariant);
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT4 = new Hashtable(new
 myCultureComparer(myCul));
        myHT4.Add("FIRST", "Hello");
        myHT4.Add("SECOND", "World");
        myHT4.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));
        Console.WriteLine("first is in myHT4: {0}",
 myHT4.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myComparer : IEqualityComparer
{
public:
    virtual bool Equals(Object^ x, Object^ y) 
    {
        return x->Equals(y);
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

ref class myCultureComparer : IEqualityComparer
{
private:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

    virtual bool Equals(Object^ x, Object^ y) 
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

int main()
{
   
   // Create a hash table using the default hash code provider and the
 default comparer.
   Hashtable^ myHT1 = gcnew Hashtable((IEqualityComparer^)nullptr);
   myHT1->Add( "FIRST", "Hello" );
   myHT1->Add( "SECOND", "World" );
   myHT1->Add( "THIRD", "!" );
   
   // Create a hash table using the specified IEqualityComparer that
 uses
   // the default Object.Equals to determine equality.
   Hashtable^ myHT2 = gcnew Hashtable(gcnew myComparer());
   myHT2->Add( "FIRST", "Hello" );
   myHT2->Add( "SECOND", "World" );
   myHT2->Add( "THIRD", "!" );
   
   // Create a hash table using a case-insensitive hash code provider
 and
   // case-insensitive comparer based on the InvariantCulture.
   Hashtable^ myHT3 = gcnew Hashtable(
            CaseInsensitiveHashCodeProvider::DefaultInvariant,
            CaseInsensitiveComparer::DefaultInvariant);
   myHT3->Add( "FIRST", "Hello" );
   myHT3->Add( "SECOND", "World" );
   myHT3->Add( "THIRD", "!" );
   
   // Create a hash table using an IEqualityComparer that is based on
   // the Turkish culture (tr-TR) where "I" is not the uppercase
   // version of "i".
   CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
   Hashtable^ myHT4 = gcnew Hashtable( gcnew myCultureComparer(myCul) );
   myHT4->Add( "FIRST", "Hello" );
   myHT4->Add( "SECOND", "World" );
   myHT4->Add( "THIRD", "!" );
   
   // Search for a key in each hash table.
   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey(
 "first" ) );
   Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey(
 "first" ) );
}

/* 
This code produces the following output.  Results vary depending on the system's
 culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Hashtable コンストラクタ (IDictionary, IEqualityComparer)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したディクショナリの要素新しHashtable オブジェクトコピーすることによって、Hashtable クラス新しインスタンス初期化します。新しHashtable オブジェクトは、コピーされ要素数に等し初期量を備えており、既定テーブル占有率および指定した IEqualityComparer オブジェクト使用します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    d As IDictionary, _
    equalityComparer As IEqualityComparer _
)
Dim d As IDictionary
Dim equalityComparer As IEqualityComparer

Dim instance As New Hashtable(d,
 equalityComparer)
public Hashtable (
    IDictionary d,
    IEqualityComparer equalityComparer
)
public:
Hashtable (
    IDictionary^ d, 
    IEqualityComparer^ equalityComparer
)
public Hashtable (
    IDictionary d, 
    IEqualityComparer equalityComparer
)
public function Hashtable (
    d : IDictionary, 
    equalityComparer : IEqualityComparer
)

パラメータ

d

新しい Hashtable オブジェクトコピーする IDictionary オブジェクト

equalityComparer

Hashtable使用するハッシュ コード プロバイダ比較演算子定義する IEqualityComparer オブジェクト

または

既定ハッシュ コード プロバイダおよび既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。既定ハッシュ コード プロバイダは、各キーの Object.GetHashCode の実装です。また、既定比較演算子は各キーの Object.Equals の実装です。

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

解説解説

初期量は、コピー元のディクショナリ内の要素数に設定されます。容量は、必要に応じてテーブル占有率基づいて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

IEqualityComparer オブジェクトには、ハッシュ コード プロバイダおよび比較演算子含まれます。IEqualityComparerHashtable コンストラクタ使用される場合Hashtable オブジェクトキーとして使用されるオブジェクトは、Object.GetHashCode メソッドおよび Object.Equals メソッドオーバーライドする必要はありません。

ハッシュ コード プロバイダは、Hashtable 内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

IEqualityComparer により、大文字と小文字区別せずに文字列の検索を行うようなシナリオ可能になります

新しHashtable要素は、列挙子が IDictionary オブジェクト反復処理するのと同じ順序並べ替えられます。

このコンストラクタは O(n) 操作です。ここで、nd パラメータ内の要素数です。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL)

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL,
 New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL,
 New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(mySL, new
 myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, new
 myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
    static void Main()
    {
        // Create the dictionary.
        SortedList^ mySL = gcnew SortedList();
        mySL->Add("FIRST", "Hello");
        mySL->Add("SECOND", "World");
        mySL->Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable^ myHT2 = gcnew Hashtable(mySL, gcnew myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(mySL, gcnew myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console::WriteLine("first is in myHT1: {0}",
 myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}",
 myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}",
 myHT3->ContainsKey("first"));
    }
};

int main()
{
    SamplesHashtable::Main();
};

/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Hashtable クラス
Hashtable メンバ
System.Collections 名前空間
IDictionary
IEqualityComparer

Hashtable コンストラクタ (Int32, IEqualityComparer)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定した初期量と IEqualityComparer、および既定テーブル占有率使用してHashtable クラス新しい空のインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    capacity As Integer, _
    equalityComparer As IEqualityComparer _
)
Dim capacity As Integer
Dim equalityComparer As IEqualityComparer

Dim instance As New Hashtable(capacity,
 equalityComparer)
public Hashtable (
    int capacity,
    IEqualityComparer equalityComparer
)
public:
Hashtable (
    int capacity, 
    IEqualityComparer^ equalityComparer
)
public Hashtable (
    int capacity, 
    IEqualityComparer equalityComparer
)
public function Hashtable (
    capacity : int, 
    equalityComparer : IEqualityComparer
)

パラメータ

capacity

Hashtable オブジェクト初期状態格納できる要素概数

equalityComparer

Hashtable使用するハッシュ コード プロバイダ比較演算子定義する IEqualityComparer オブジェクト

または

既定ハッシュ コード プロバイダおよび既定比較演算子使用する場合null 参照 (Visual Basic では Nothing)。既定ハッシュ コード プロバイダは、各キーの Object.GetHashCode の実装です。また、既定比較演算子は各キーの Object.Equals の実装です。

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説

初期量を指定すると、Hashtable オブジェクト要素追加するときに、サイズ変更操作何度も実行する必要がなくなります容量は、必要に応じてテーブル占有率基づいて自動的に増加します。

テーブル占有率は、バケット数に対す要素数の最大比率です。テーブル占有率小さくすると、検索速度速くなりますが、メモリ消費量増加します。

実際テーブル占有率指定した占有率達すると、バケット数は、現在のバケット数の 2 倍より大きい範囲最小素数になるように、自動的に増やされます。

IEqualityComparer オブジェクトには、ハッシュ コード プロバイダおよび比較演算子含まれます。IEqualityComparerHashtable コンストラクタ使用される場合Hashtableキーとして使用されるオブジェクトは、Object.GetHashCode メソッドおよび Object.Equals メソッドオーバーライドする必要はありません。

ハッシュ コード プロバイダは、Hashtable 内のキーハッシュ コード提供します既定ハッシュ コード プロバイダは、キーObject.GetHashCode実装です。

比較演算子2 つキー等しかどうか判断しますHashtable 内のすべてのキー一意である必要があります既定比較演算子は、キーObject.Equals実装です。

IEqualityComparer により、大文字と小文字区別せずに文字列の検索を行うようなシナリオ可能になります

このコンストラクタは O(n) 操作です。ここで、ncapacity パラメータです。

使用例使用例

異なHashtable コンストラクタ使用してハッシュ テーブル作成し、各ハッシュ テーブル動作違いを示すコード例次に示します。同じ要素格納されていたとしても、動作異なることがわかります

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal
 myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal
 x As Object, ByVal y As
 Object) _
        As Boolean Implements
 IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal
 obj As Object) _
        As Integer Implements
 IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(3)
      myHT1.Add("FIRST", "Hello")
      myHT1.Add("SECOND", "World")
      myHT1.Add("THIRD", "!")

      ' Create a hash table using the specified IEqualityComparer that
 uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(3,
 New myCultureComparer())
      myHT2.Add("FIRST", "Hello")
      myHT2.Add("SECOND", "World")
      myHT2.Add("THIRD", "!")

      ' Create a hash table using an IEqualityComparer that is based
 on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(3,
 New myCultureComparer(myCul))
      myHT3.Add("FIRST", "Hello")
      myHT3.Add("SECOND", "World")
      myHT3.Add("THIRD", "!")

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object
 x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer
 that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine
 equality.
        Hashtable myHT2 = new Hashtable(3, new
 myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based
 on
        // the Turkish culture (tr-TR) where "I" is not the
 uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, new
 myCultureComparer(myCul));
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}",
 myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}",
 myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}",
 myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Hashtable プロパティ


パブリック プロパティパブリック プロパティ

( プロテクト プロパティ参照)
  名前 説明
パブリック プロパティ Values Hashtable 内の値を格納している ICollection取得します
プロテクト プロパティプロテクト プロパティ
参照参照

関連項目

Hashtable クラス
System.Collections 名前空間
IDictionary
IHashCodeProvider
Object.GetHashCode
Object.Equals
DictionaryEntry 構造体
System.Collections.Generic.Dictionary
IEqualityComparer

Hashtable メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add 指定したキーおよび値を持つ要素を Hashtable に追加します
パブリック メソッド Clear Hashtable からすべての要素削除します
パブリック メソッド Clone Hashtable簡易コピー作成します
パブリック メソッド Contains Hashtable特定のキー格納されているかどうか判断します
パブリック メソッド ContainsKey Hashtable特定のキー格納されているかどうか判断します
パブリック メソッド ContainsValue Hashtable特定の値格納されているかどうか判断します
パブリック メソッド CopyTo 1 次元Array インスタンス指定したインデックスHashtable要素コピーします
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator Hashtable反復処理する IDictionaryEnumerator を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetObjectData ISerializable インターフェイス実装し、Hashtableシリアル化するために必要なデータ返します
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド OnDeserialization ISerializable インターフェイス実装し、逆シリアル化完了したときに逆シリアル化イベント発生させます
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド Remove 指定したキー持つ要素Hashtable から削除します
パブリック メソッド Synchronized Hashtable 用の同期された (スレッド セーフな) ラッパー返します
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクション反復処理する列挙子を返します
参照参照

関連項目

Hashtable クラス
System.Collections 名前空間
IDictionary
IHashCodeProvider
Object.GetHashCode
Object.Equals
DictionaryEntry 構造体
System.Collections.Generic.Dictionary
IEqualityComparer

Hashtable メンバ

キーハッシュ コード基づいて編成された、キー/値ペアコレクション表します

Hashtable データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
パブリック プロパティパブリック プロパティ
( プロテクト プロパティ参照)
  名前 説明
パブリック プロパティ Values Hashtable 内の値を格納している ICollection取得します
プロテクト プロパティプロテクト プロパティ
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add 指定したキーおよび値を持つ要素Hashtable追加します
パブリック メソッド Clear Hashtable からすべての要素削除します
パブリック メソッド Clone Hashtable簡易コピー作成します
パブリック メソッド Contains Hashtable特定のキー格納されているかどうか判断します
パブリック メソッド ContainsKey Hashtable特定のキー格納されているかどうか判断します
パブリック メソッド ContainsValue Hashtable特定の値格納されているかどうか判断します
パブリック メソッド CopyTo 1 次元Array インスタンス指定したインデックスHashtable要素コピーします
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator Hashtable反復処理する IDictionaryEnumerator を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetObjectData ISerializable インターフェイス実装し、Hashtableシリアル化するために必要なデータ返します
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド OnDeserialization ISerializable インターフェイス実装し、逆シリアル化完了したときに逆シリアル化イベント発生させます
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド Remove 指定したキー持つ要素Hashtable から削除します
パブリック メソッド Synchronized Hashtable 用の同期された (スレッド セーフな) ラッパー返します
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクション反復処理する列挙子を返します
参照参照

関連項目

Hashtable クラス
System.Collections 名前空間
IDictionary
IHashCodeProvider
Object.GetHashCode
Object.Equals
DictionaryEntry 構造体
System.Collections.Generic.Dictionary
IEqualityComparer

ハッシュ表

読み方はっしゅひょう
【英】:hash table

値(キー)をもつn\, 個の要素集合対し, 挿入削除検索3つの機能高速化したデータ構造. 値をハッシュキーと呼ばれるいくつかのキー分類し, それぞれの要素連結リストなどにより保持する. 挿入削除をO(1)\, 時間行い, 検索は, 最悪場合はO(n)\, となるが, ハッシュキーを適切に設定すれば平均的に O(1)\, となることが多い. 辞書データ保持多く使われ, 辞書データ頭文字をハッシュキーとして保持する, などの例がある.


ハッシュテーブル

(hash table から転送)

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2022/10/18 03:00 UTC 版)

ハッシュテーブル (: hash table) は、キーと値の組(エントリと呼ぶ)を複数個格納し、キーに対応する値をすばやく参照するためのデータ構造ハッシュ表ともいう。ハッシュテーブルは連想配列集合の効率的な実装のうち1つである。




「ハッシュテーブル」の続きの解説一覧


英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「hash table」の関連用語

hash tableのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



hash tableのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
デジタル大辞泉デジタル大辞泉
(C)Shogakukan Inc.
株式会社 小学館
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.
日本オペレーションズ・リサーチ学会日本オペレーションズ・リサーチ学会
Copyright (C) 2024 (社)日本オペレーションズ・リサーチ学会 All rights reserved.
ウィキペディアウィキペディア
All text is available under the terms of the GNU Free Documentation License.
この記事は、ウィキペディアのハッシュテーブル (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。 Weblio辞書に掲載されているウィキペディアの記事も、全てGNU Free Documentation Licenseの元に提供されております。

©2024 GRAS Group, Inc.RSS