forked from TensorStack-AI/TensorStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequenceCollection.cs
More file actions
116 lines (98 loc) · 3.42 KB
/
SequenceCollection.cs
File metadata and controls
116 lines (98 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) TensorStack. All rights reserved.
// Licensed under the Apache 2.0 License.
using System.Collections;
using System.Collections.Generic;
namespace TensorStack.TextGeneration
{
public class SequenceCollection : IEnumerable<Sequence>
{
private readonly List<Sequence> _sequences;
/// <summary>
/// Initializes a new instance of the <see cref="SequenceCollection"/> class.
/// </summary>
/// <param name="initalSize">Size of the inital.</param>
public SequenceCollection(int initalSize = 1)
{
_sequences = new List<Sequence>(initalSize);
}
/// <summary>
/// Initializes a new instance of the <see cref="SequenceCollection"/> class.
/// </summary>
/// <param name="initialSequence">The initial sequence.</param>
/// <param name="initalSize">Size of the inital.</param>
public SequenceCollection(Sequence initialSequence, int initalSize = 1)
{
_sequences = new List<Sequence>(initalSize) { initialSequence };
}
/// <summary>
/// Gets the count.
/// </summary>
public int Count => _sequences.Count;
/// <summary>
/// Adds the specified sequence.
/// </summary>
/// <param name="sequence">The sequence.</param>
public void Add(Sequence sequence)
{
if (_sequences.Contains(sequence))
return;
_sequences.Add(sequence);
}
/// <summary>
/// Removes the specified sequences.
/// </summary>
/// <param name="sequences">The sequences.</param>
public void Remove(SequenceCollection sequences)
{
foreach (var sequence in sequences)
{
_sequences.Remove(sequence);
}
}
/// <summary>
/// Removes the specified sequences.
/// </summary>
/// <param name="sequences">The sequences.</param>
public void Remove(params Sequence[] sequences)
{
foreach (var sequence in sequences)
{
_sequences.Remove(sequence);
}
}
/// <summary>
/// Clears and dispose sequences.
/// </summary>
public void Clear()
{
_sequences.Dispose();
_sequences.Clear();
}
/// <summary>
/// Gets or sets the <see cref="Sequence"/> at the specified index.
/// </summary>
/// <param name="index">The index.</param>
/// <returns>Sequence.</returns>
public Sequence this[int index]
{
get { return _sequences[index]; }
set { _sequences[index] = value; }
}
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>An enumerator that can be used to iterate through the collection.</returns>
public IEnumerator<Sequence> GetEnumerator()
{
return _sequences.GetEnumerator();
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}