Re: find closest item in keyed collection

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Ben, Tested that on the original q, as I understand it, the "close
find" shuld give 40 if asked 39...

Array i2 = Array.CreateInstance(typeof(short),7);

// given 20, 30, 40, 50, 60, 70, 80

i2.SetValue((short)20, 0);
i2.SetValue((short)30, 1);
i2.SetValue((short)40, 2);
i2.SetValue((short)50, 3);
i2.SetValue((short)60, 4);
i2.SetValue((short)70, 5);
i2.SetValue((short)80, 6);

// given 35
int j = Array.BinarySearch(i2, (short)35);
if (j < -1)
j = ~j-1;

Console.WriteLine("35 -> " +
i2.GetValue(j).ToString()); // 30

// testing low 10
j = Array.BinarySearch(i2, (short)10);
if (j < -1)
j = ~j - 1;
else // Oops
j = 0;
Console.WriteLine("10 -> " +
i2.GetValue(j).ToString()); // 20

// testing high 100
j = Array.BinarySearch(i2, (short)100);
if (j < -1)
j = ~j - 1;

Console.WriteLine("100 -> " +
i2.GetValue(j).ToString()); // 80

// testing close 39
j = Array.BinarySearch(i2, (short)39);
if (j < -1)
j = ~j - 1;

Console.WriteLine("39 -> " +
i2.GetValue(j).ToString()); // 30 = Fail, should return 40 or what?

//CY
.



Relevant Pages

  • Re: 2.6.20.3 AMD64 oops in CFQ code
    ... Not a cfq failure, but I have been able to reproduce a different oops ... When a raid5 array shuts down, it clears mddev->private, but doesn't ... it will try to dereference mddev->private and Oops. ... But I don't think it is related to the cfq problem as this one is only ...
    (Linux-Kernel)
  • MD Oops on boot with 2.6.2-rc1-mm3
    ... I get an Oops on boot with 2.6.2-rc1-mm3, trying to boot from a RAID1 ... MD root partition with two disks in the array; ...
    (Linux-Kernel)
  • Re: 2.6.17-mm5
    ... Actually, is there any more of the trace, like what was going on just ... before the oops? ... It looks very like a lifetime issue (i.e. md thinks the array is dead ... would be nice to know what the outstanding command might have been. ...
    (Linux-Kernel)
  • Please revert 5b479c91da90eef605f851508744bfe8269591a0 (md partition rescan)
    ... It causes an oops when auto-detecting raid arrays, ... easy to fix. ... I cannot really open the array at this point as I ... different bdev somehow, and on array assembly, a new bdev, or gendisk ...
    (Linux-Kernel)
  • Re: PROBLEM: APIC on a Pentium Classic SMP, 2.4.21-pre2 and 2.4.21-pre3 ksymoops
    ... >> You didn't run that through ksymoops and post it, ... a dynamically allocated array. ... Fixing the oops is easy, ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)