-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathChunkNode.cs
More file actions
79 lines (68 loc) · 1.81 KB
/
ChunkNode.cs
File metadata and controls
79 lines (68 loc) · 1.81 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
using System.Diagnostics;
namespace Waher.Runtime.Collections
{
/// <summary>
/// Node referencing a chunk in a <see cref="ChunkedList{T}"/>
/// </summary>
[DebuggerDisplay("Count = {Count}, Start = {Start}, Pos = {Pos}, Size = {Size}")]
[DebuggerTypeProxy(typeof(ChunkNodeDebugView<>))]
public class ChunkNode<T>
{
private readonly ChunkedList<T>.Chunk chunk;
/// <summary>
/// Node referencing a chunk in a <see cref="ChunkedList{T}"/>
/// </summary>
/// <param name="Chunk">Chunk</param>
internal ChunkNode(ChunkedList<T>.Chunk Chunk)
{
this.chunk = Chunk;
}
/// <summary>
/// Next chunk
/// </summary>
public ChunkNode<T> Next => this.chunk.Next?.Node;
/// <summary>
/// Previous chunk
/// </summary>
public ChunkNode<T> Prev => this.chunk.Prev?.Node;
/// <summary>
/// Array of elements in chunk.
/// </summary>
public T[] Elements => this.chunk.Elements;
/// <summary>
/// Size of chunk.
/// </summary>
public int Size => this.chunk.Size;
/// <summary>
/// Index of first element in chunk.
/// </summary>
public int Start => this.chunk.Start;
/// <summary>
/// Index after the last element in chunk.
/// </summary>
public int Pos => this.chunk.Pos;
/// <summary>
/// Number of elements in chunk.
/// </summary>
public int Count => this.chunk.Pos - this.chunk.Start;
/// <summary>
/// String representation of chunk.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return this.chunk.ToString();
}
/// <summary>
/// Access directly into the chunk. Valid indices are from <see cref="Start"/>
/// to <see cref="Pos"/>-1.
/// </summary>
/// <param name="Index"></param>
/// <returns></returns>
public T this[int Index]
{
get => this.chunk[Index];
set => this.chunk[Index] = value;
}
}
}