blob: ffab57711569e607641068c9ab03ee7e61c2abcd [file] [log] [blame]
Jens Geyeraa0c8b32019-01-28 23:27:45 +01001// Licensed to the Apache Software Foundation(ASF) under one
2// or more contributor license agreements.See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18using System.Collections;
19using System.Collections.Generic;
20
21namespace Thrift.Collections
22{
23 // ReSharper disable once InconsistentNaming
24 public class THashSet<T> : ICollection<T>
25 {
Jens Geyer5a17b132019-05-26 15:53:37 +020026 private readonly HashSet<T> Items;
Jens Geyeraa0c8b32019-01-28 23:27:45 +010027
Jens Geyer5a17b132019-05-26 15:53:37 +020028 public THashSet()
29 {
30 Items = new HashSet<T>();
31 }
32
33 public THashSet(int capacity)
34 {
35 // TODO: uncomment capacity when NET Standard also implements it
36 Items = new HashSet<T>(/*capacity*/);
37 }
38
39 public int Count => Items.Count;
Jens Geyeraa0c8b32019-01-28 23:27:45 +010040
41 public bool IsReadOnly => false;
42
43 public void Add(T item)
44 {
Jens Geyer5a17b132019-05-26 15:53:37 +020045 Items.Add(item);
Jens Geyeraa0c8b32019-01-28 23:27:45 +010046 }
47
48 public void Clear()
49 {
Jens Geyer5a17b132019-05-26 15:53:37 +020050 Items.Clear();
Jens Geyeraa0c8b32019-01-28 23:27:45 +010051 }
52
53 public bool Contains(T item)
54 {
Jens Geyer5a17b132019-05-26 15:53:37 +020055 return Items.Contains(item);
Jens Geyeraa0c8b32019-01-28 23:27:45 +010056 }
57
58 public void CopyTo(T[] array, int arrayIndex)
59 {
Jens Geyer5a17b132019-05-26 15:53:37 +020060 Items.CopyTo(array, arrayIndex);
Jens Geyeraa0c8b32019-01-28 23:27:45 +010061 }
62
63 public IEnumerator GetEnumerator()
64 {
Jens Geyer5a17b132019-05-26 15:53:37 +020065 return Items.GetEnumerator();
Jens Geyeraa0c8b32019-01-28 23:27:45 +010066 }
67
68 IEnumerator<T> IEnumerable<T>.GetEnumerator()
69 {
Jens Geyer5a17b132019-05-26 15:53:37 +020070 return ((IEnumerable<T>) Items).GetEnumerator();
Jens Geyeraa0c8b32019-01-28 23:27:45 +010071 }
72
73 public bool Remove(T item)
74 {
Jens Geyer5a17b132019-05-26 15:53:37 +020075 return Items.Remove(item);
Jens Geyeraa0c8b32019-01-28 23:27:45 +010076 }
77 }
Jens Geyer5a17b132019-05-26 15:53:37 +020078}