From f3f86fd1fe0fb288356bff78f8a6fa2edf89e3fc Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 16 Oct 2024 08:10:14 -0600 Subject: Squashed 'lib/lwip/lwip/' content from commit 0a0452b2c39b git-subtree-dir: lib/lwip/lwip git-subtree-split: 0a0452b2c39bdd91e252aef045c115f88f6ca773 --- .../LwipMibCompiler/SharpSnmpLib/Mib/ValueMap.cs | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 contrib/apps/LwipMibCompiler/SharpSnmpLib/Mib/ValueMap.cs (limited to 'contrib/apps/LwipMibCompiler/SharpSnmpLib/Mib/ValueMap.cs') diff --git a/contrib/apps/LwipMibCompiler/SharpSnmpLib/Mib/ValueMap.cs b/contrib/apps/LwipMibCompiler/SharpSnmpLib/Mib/ValueMap.cs new file mode 100644 index 00000000000..48842356a20 --- /dev/null +++ b/contrib/apps/LwipMibCompiler/SharpSnmpLib/Mib/ValueMap.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; + +namespace Lextm.SharpSnmpLib.Mib +{ + public class ValueMap : Dictionary + { + public ValueMap() + { + } + + /// + /// Returns the values of the map as continuous range. At best as one range. + /// + /// + public ValueRanges GetContinousRanges() + { + ValueRanges result = new ValueRanges(); + + if (this.Count > 0) + { + List values = new List(this.Keys); + values.Sort(); + + Int64 last = values[0]; + Int64 offset = values[0]; + for (int i=1; i + /// Gets the highest value contained in this value map. + /// + /// + public Int64 GetHighestValue() + { + Int64 result = 0; + + foreach (Int64 value in this.Keys) + { + if (value > result) + { + result = value; + } + } + + return result; + } + + /// + /// Interprets the single values as bit positions and creates a mask of it. + /// + /// + public UInt32 GetBitMask() + { + UInt32 result = 0; + + foreach (Int64 key in this.Keys) + { + if (key < 0) + { + throw new NotSupportedException("Negative numbers are not allowed for Bits!"); + } + if (key > 31) + { + throw new NotSupportedException("Bits with more than 32 bits are not supported!"); + } + + result |= (UInt32)(1 << (int)key); + } + + return result; + } + } +} -- cgit v1.2.3