Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ListBoundExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 namespace SiliconStudio.Paradox.Games
7 {
8  /// <summary>
9  /// Helper functions to determine lower and upper bounds in a sorted list.
10  /// </summary>
11  static class ListBoundExtensions
12  {
13  // http://www.cplusplus.com/reference/algorithm/lower_bound/
14  public static int LowerBound<TItem>(this List<TItem> list, TItem value, IComparer<TItem> comparer, int index, int count)
15  {
16  while (count > 0)
17  {
18  int half = count >> 1;
19  int middle = index + half;
20  if (comparer.Compare(list[middle], value) < 0)
21  {
22  index = middle + 1;
23  count = count - half - 1;
24  }
25  else
26  count = half;
27  }
28  return index;
29  }
30 
31  // http://www.cplusplus.com/reference/algorithm/upper_bound/
32  public static int UpperBound<TItem>(this List<TItem> list, TItem value, IComparer<TItem> comparer, int index, int count)
33  {
34  while (count > 0)
35  {
36  int half = count >> 1;
37  int middle = index + half;
38  if (comparer.Compare(value, list[middle]) >= 0)
39  {
40  index = middle + 1;
41  count = count - half - 1;
42  }
43  else
44  count = half;
45  }
46  return index;
47  }
48  }
49 }
_In_ size_t count
Definition: DirectXTexP.h:174
Helper functions to determine lower and upper bounds in a sorted list.