-
Notifications
You must be signed in to change notification settings - Fork 533
Expand file tree
/
Copy pathCosmosArray.cs
More file actions
165 lines (126 loc) · 5.91 KB
/
CosmosArray.cs
File metadata and controls
165 lines (126 loc) · 5.91 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.CosmosElements
{
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Query.Core.Pipeline.Distinct;
using UInt128 = Cosmos.UInt128;
#if INTERNAL
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable SA1600 // Elements should be documented
#pragma warning disable SA1601 // Partial elements should be documented
public
#else
internal
#endif
abstract partial class CosmosArray : CosmosElement, IReadOnlyList<CosmosElement>, IEquatable<CosmosArray>, IComparable<CosmosArray>
{
public static readonly CosmosArray Empty = new EagerCosmosArray(Enumerable.Empty<CosmosElement>());
private const uint HashSeed = 2533142560;
protected CosmosArray()
: base()
{
}
public abstract int Count { get; }
public abstract CosmosElement this[int index] { get; }
public override void Accept(ICosmosElementVisitor cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);
public override bool Equals(CosmosElement? cosmosElement) => cosmosElement is CosmosArray cosmosArray && this.Equals(cosmosArray);
public bool Equals(CosmosArray? cosmosArray)
{
if (cosmosArray is null)
{
return false;
}
if (this.Count != cosmosArray.Count)
{
return false;
}
IEnumerable<(CosmosElement, CosmosElement)> itemPairs = this.Zip(cosmosArray, (first, second) => (first, second));
foreach ((CosmosElement thisItem, CosmosElement otherItem) in itemPairs)
{
if (thisItem != otherItem)
{
return false;
}
}
return true;
}
public override int GetHashCode()
{
uint hash = HashSeed;
// Incorporate all the array items into the hash.
for (int index = 0; index < this.Count; index++)
{
CosmosElement arrayItem = this[index];
hash = MurmurHash3.Hash32(arrayItem.GetHashCode(), hash);
}
return (int)hash;
}
public int CompareTo(CosmosArray? cosmosArray)
{
if (cosmosArray is null)
{
return 1;
}
Cosmos.UInt128 hash1 = DistinctHash.GetHash(this);
Cosmos.UInt128 hash2 = DistinctHash.GetHash(cosmosArray);
return UInt128BinaryComparer.Singleton.Compare(hash1, hash2);
}
public static CosmosArray Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosArray(jsonNavigator, jsonNavigatorNode);
public static CosmosArray Create(IEnumerable<CosmosElement> cosmosElements) => new EagerCosmosArray(cosmosElements);
public static CosmosArray Create(params CosmosElement[] cosmosElements) => new EagerCosmosArray(cosmosElements);
public static CosmosArray Create() => CosmosArray.Empty;
public abstract Enumerator GetEnumerator();
IEnumerator<CosmosElement> IEnumerable<CosmosElement>.GetEnumerator() => this.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public static new CosmosArray CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosArray>(buffer);
public static new CosmosArray Parse(string json) => CosmosElement.Parse<CosmosArray>(json);
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosArray cosmosArray) => CosmosElement.TryCreateFromBuffer<CosmosArray>(buffer, out cosmosArray);
public static bool TryParse(string json, out CosmosArray cosmosArray) => CosmosElement.TryParse<CosmosArray>(json, out cosmosArray);
public static new class Monadic
{
public static TryCatch<CosmosArray> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosArray>(buffer);
public static TryCatch<CosmosArray> Parse(string json) => CosmosElement.Monadic.Parse<CosmosArray>(json);
}
public struct Enumerator : IEnumerator<CosmosElement>
{
private List<CosmosElement>.Enumerator innerEnumerator;
internal Enumerator(List<CosmosElement>.Enumerator innerEnumerator)
{
this.innerEnumerator = innerEnumerator;
}
public CosmosElement Current => this.innerEnumerator.Current;
object IEnumerator.Current => this.innerEnumerator.Current;
public void Dispose()
{
this.innerEnumerator.Dispose();
}
public bool MoveNext()
{
return this.innerEnumerator.MoveNext();
}
public void Reset()
{
throw new NotImplementedException();
}
}
}
#if INTERNAL
#pragma warning restore SA1601 // Partial elements should be documented
#pragma warning restore SA1600 // Elements should be documented
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#endif
}