Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 1 | // 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 | |
| 18 | using System.Collections; |
| 19 | using System.Collections.Generic; |
| 20 | |
| 21 | namespace Thrift.Collections |
| 22 | { |
| 23 | // ReSharper disable once InconsistentNaming |
| 24 | public class THashSet<T> : ICollection<T> |
| 25 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 26 | private readonly HashSet<T> Items; |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 27 | |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 28 | 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 Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 40 | |
| 41 | public bool IsReadOnly => false; |
| 42 | |
| 43 | public void Add(T item) |
| 44 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 45 | Items.Add(item); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | public void Clear() |
| 49 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 50 | Items.Clear(); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public bool Contains(T item) |
| 54 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 55 | return Items.Contains(item); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | public void CopyTo(T[] array, int arrayIndex) |
| 59 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 60 | Items.CopyTo(array, arrayIndex); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public IEnumerator GetEnumerator() |
| 64 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 65 | return Items.GetEnumerator(); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | IEnumerator<T> IEnumerable<T>.GetEnumerator() |
| 69 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 70 | return ((IEnumerable<T>) Items).GetEnumerator(); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | public bool Remove(T item) |
| 74 | { |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 75 | return Items.Remove(item); |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 76 | } |
| 77 | } |
Jens Geyer | 5a17b13 | 2019-05-26 15:53:37 +0200 | [diff] [blame] | 78 | } |