This question already has answers here:
Is there a Lower Bound function on a SortedList<K ,V>?
(6 answers)
Closed 9 years ago.
I need a built-in datastructure in C# that has functionality similar to std::set (or std::map) in c++. What is important to me is that the structure should be sorted(thus Dictionary will not do here) and has a method similar to lower_bound(i.e. return first element with value at least v). I will also need to insert and delete elements from the structure. If possible I need these operations to have complexity O(log(n)). Could you please point me to the appropriate datastructure in C#?
I suspect you are looking for SortedSet in terms of a similar data structure to std::set.
This article goes into its performance characteristics.
A lower_bound functionality seems to be possible using SortedSet.GetViewBetween but has a worse complexity than the desired O(log(n)) according to this discussion.
Related
This question already has answers here:
C# LINQ find duplicates in List
(13 answers)
Closed 5 years ago.
I was hoping to do something like:
int[] locations;
do
{/*edit locations to only contain one int in array of same value*/}
while (locations.Where(val, secondVal => val == secondVal).count > 1)
And I highly feel like I've done something of the sort in the past, perhaps it was with a list and it doesn't function the same way with an array but I can't seem to find my example anywhere.
I feel that the code snip explains well enough my intentions, but it doesn't work, would someone be able to help? Thanks.
I'll keep searching online but if someone could help it would obviously speed up my search.
You should look to this answer:
C# LINQ find duplicates in List
Just group elements by its value and then get the list
GroupBy(x=>x).Where(g=>g.Count()>1)
This question already has answers here:
MongoDB: Is it possible to make a case-insensitive query?
(27 answers)
Closed 8 years ago.
I have a collection like
{
"email" : "sh#Gmail.com"
}
My query should be like , it has to find matching email irrespective of case whether its capital or small but it should match exactly.
In sql we will do like where Lower(strEmail) = Lower(#emailParameterPassed) to satisfy this same.
UPDATE
I got it here.
Thanks
How to achieve this in mongoDb?
I am using c# native driver with mongoDb ?
Nonetheless the answer you are duplicating will give you a correct result, it is not a good idea to do queries like this. Why should you use regex (without indexes ) if you can use normal equal and take advantage of indexes?
There is no difference between sh#Gmail.com and sh#gmail.com so why not to store them in a canonical form in the first place and then to use normal search. To change all the documents, you can refer to my previous answer.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to calculate or approximate the median of a list without storing the list
I want to apply using C# an algorithm to find the median value using selection/quick sort. But I do not want to sort the whole array in order to get the median.
Can I do it?
Wikipedia's entry on Selection Algorithm gives various alternatives, including the Median of Medians approach, which would seem to fit your requirements. In particular, it has a worst-case performance of O(n).
This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
a curious c# syntax
So I've seen some code around and a few of them use a ? after the type, like this:
private Point? loc = null;
So I'm wondering if Point? is different than Point (can't put a question mark at the end of my sentence or I'll confuse you guys ... :] ). The language I'm using is C# by the way.
T? is a shorthand (in C#) for Nullable<T> - so Point? is another way of writing Nullable<Point> or example.
See sections 1.3 and 4.1 of the C# 3 language spec - and various other places, to be honest - for more details. See the docs for System.Nullable<T> for more information from the framework side of things. Or read chapter 4 of C# in Depth :) (Unfortunately it's not one of the free chapters.)
(This question is bound to be a duplicate, but I don't have the energy to find it right now.)
Point? is the same as Nullable<Point>. It allows you to assign null to value types, such as structs.
It means the type can accept its' value and null.
This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
count vs length vs size in a collection
Am I overlooking a semantic difference between "Length" and "Count", or did perhaps some implementation detail in the .NET Framework require different names for these similar concepts? Given the close attention that was paid to naming and everything else in the framework, there must be a good explanation.
Actually these are similar but not identical concepts. Since an array's length is static and its memory gets allocated once and for all (int[] intarray = new int[10]; // allocates the memory for 10 ints) the Length property is quite static. Otherwise Enumerables like a List might not know their Length beforehand so the Property Count will in some way "count" the length (you might iterate through all associated elements in an enumerable). That's the basic difference.