STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
ValueMap.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 
4 namespace Lextm.SharpSnmpLib.Mib
5 {
6  public class ValueMap : Dictionary<Int64, string>
7  {
8  public ValueMap()
9  {
10  }
11 
17  {
18  ValueRanges result = new ValueRanges();
19 
20  if (this.Count > 0)
21  {
22  List<Int64> values = new List<long>(this.Keys);
23  values.Sort();
24 
25  Int64 last = values[0];
26  Int64 offset = values[0];
27  for (int i=1; i<values.Count; i++)
28  {
29  if (values[i] != last + 1)
30  {
31  if (last == offset)
32  {
33  result.Add(new ValueRange(offset, null));
34  }
35  else
36  {
37  result.Add(new ValueRange(offset, last));
38  }
39 
40  offset = values[i];
41  }
42 
43  last = values[i];
44  }
45 
46  if (last == offset)
47  {
48  result.Add(new ValueRange(offset, null));
49  }
50  else
51  {
52  result.Add(new ValueRange(offset, last));
53  }
54  }
55 
56  return result;
57  }
58 
63  public Int64 GetHighestValue()
64  {
65  Int64 result = 0;
66 
67  foreach (Int64 value in this.Keys)
68  {
69  if (value > result)
70  {
71  result = value;
72  }
73  }
74 
75  return result;
76  }
77 
82  public UInt32 GetBitMask()
83  {
84  UInt32 result = 0;
85 
86  foreach (Int64 key in this.Keys)
87  {
88  if (key < 0)
89  {
90  throw new NotSupportedException("Negative numbers are not allowed for Bits!");
91  }
92  if (key > 31)
93  {
94  throw new NotSupportedException("Bits with more than 32 bits are not supported!");
95  }
96 
97  result |= (UInt32)(1 << (int)key);
98  }
99 
100  return result;
101  }
102  }
103 }
ValueRanges GetContinousRanges()
Returns the values of the map as continous range. At best as one range.
Definition: ValueMap.cs:16
UInt32 GetBitMask()
Interprets the single values as bit positions and creates a mask of it.
Definition: ValueMap.cs:82
Int64 GetHighestValue()
Gets the highest value contained in this value map.
Definition: ValueMap.cs:63