!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / Statoscope / Statoscope / ListExtensions.cs
blob80c81ebcac0e627aa84bb3c3902c7a60fb1572bf
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System.Collections.Generic;
5 namespace Statoscope
7 static class ListExtensions
9 public delegate bool LessThan<T>(T a, T b);
10 public delegate X Map<T, X>(T v);
12 public static int MappedBinarySearchIndex<T, X>(this List<T> lst, X v, Map<T, X> map, LessThan<X> lt)
14 int l = 0, u = lst.Count;
16 while ((u - l) > 1)
18 int d = u - l;
19 int m = l + d / 2;
21 if (lt(v, map(lst[m])))
23 u = m;
25 else
27 l = m;
31 return l;
35 static class ArrayExtensions
37 public static int MappedBinarySearchIndex<T, X>(this T[] lst, X v, ListExtensions.Map<T, X> map, ListExtensions.LessThan<X> lt)
39 int l = 0, u = lst.Length;
41 while ((u - l) > 1)
43 int d = u - l;
44 int m = l + d / 2;
46 if (lt(v, map(lst[m])))
48 u = m;
50 else
52 l = m;
56 return l;