forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlobArrayExtensions.cs
More file actions
45 lines (40 loc) · 1.08 KB
/
Copy pathBlobArrayExtensions.cs
File metadata and controls
45 lines (40 loc) · 1.08 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
using System;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
namespace Graphical.Splines
{
public static class BlobArrayExtensions
{
public static int LowerBound<T>(ref this BlobArray<T> array, T value)
where T : struct, IComparable<T>
{
return LowerBound(ref array, value, new NativeSortExtension.DefaultComparer<T>());
}
public static int LowerBound<T, U>(ref this BlobArray<T> array, T value, U comparer)
where T : struct
where U : IComparer<T>
{
int l = 0;
int r = array.Length;
while (r > l)
{
var m = (l + r) / 2;
var c = comparer.Compare(array[m], value);
if (c == 0)
{
return l;
}
if (c < 0)
{
l = m + 1;
}
else
{
r = m;
}
}
return l - 1;
}
}
}