Not much information was given so I can’t help with something more detailed, but there is no proper data structure for this.
Indeed for its precise description of classified data structure (is a wrong term there), then you can do this manually every time before you search (or once if you can guarantee the immutability of the data collection), or you can use a structure that classifies itself as the SortedDictionary
, without this just analyzing the entire collection. But to find the next one is algorithm and not data structure. If you don’t know how to do it you have a chance to get ready using LINQ (probably Aggregate()
) or at least in the library Morelinq, there is to find a method that overcomes your need.
Then in comment something was said about space, if that is the problem is much more complex and if this is clarified it is too wide.
how so "nearest neighbor"? if it does not find a value it is not in the array, how can it have a neighbor? would make sense if it found the value, oh yes it would have at least one neighbor (before or after), you mean the nearest value (higher or lower) of a value that was not found?
– Ricardo Pontual
Yes, the closest if the value is not in the array (which is almost always the case)
– Matheus Lacerda Bezerra
and what values are in this vector? simple values, numbers, strings or are objects?
– Ricardo Pontual
Objects. I made a class that stores information from a given point in space. Hence if an X point is not in the vector (which is almost always the case), I look for the element in the vector that has the nearest point
– Matheus Lacerda Bezerra
so you need to put this class in your question to help. If you were a simple guy, a list of integers for example, you could do this with yourself
OrderBy
, orAggregate
, now as it is an object, you will have to write your own logic to do this, using Icomparer` for example, but only seeing what has in its object to give a more accurate example, the rest would only be guesses– Ricardo Pontual
I don’t know Fuzzy lists in C#. But the algorithm I know the name, it’s called Distancia Levenshtein it measures how many transformations one string needs to match another. All you have to do is scroll through a list applying this algorithm to the string that displays the Mno transformation coefficient is the nearest string.
– Augusto Vasques