|
|
All of the standard sorted collections require unique keys which violates one of OP's requirements.
|
|
|
|
|
Member 10339829 wrote: If it is almost sorted, the sorting time must be minimal. We always strive for minimal time; how many elements are in your list?
Member 10339829 wrote: The keys in collection must NOT be unique! Then they're no longer "keys", but simply values. That equates to an array of objects - so, an IComparer would sort that.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You need a collection of ... what ? And, what is the "sorting algorithm" you require/need/want ?
.NET hands you the ability to easily sort (using a QuickSort algorithm) generic Lists of value types by just invoking the 'Sort function: "All numeric types (such as Int32 and Double) implement IComparable, as do String, Char, and DateTime. Custom types should also provide their own implementation of IComparable to enable object instances to be ordered or sorted."
And, writing your own IComparable is not that difficult; for example:
If you have a TreeNode Collection:
public List<TreeNode> sTNList = new List<TreeNode>
{
new TreeNode("1"),
new TreeNode("1"),
new TreeNode("2"),
new TreeNode("4"),
new TreeNode("1"),
new TreeNode("4"),
new TreeNode("8"),
new TreeNode("2"),
new TreeNode("3")
}; You can easily define a custom IComparer Class to sort the nodes:
public class TreeNodeICompare : IComparer<TreeNode>
{
public int Compare(TreeNode x, TreeNode y)
{
return(x.Text.CompareTo(y.Text));
}
} And invoke it:
sTNList.Sort(0, sTNList.Count, new TreeNodeICompare()); See [^] for the documentation on the call to 'Sort used here. And, note: "This method uses Array.Sort, which uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal. ... On average, this method is an O(n log n) operation, where n is Count; in the worst case it is an O(n ^ 2) operation."
Using a non-unique property of a collection, like the 'Text property of a TreeNode, you avoid possible duplicate key issues that might arise with other types of collections.
Perhaps if you describe the scenario in which your collection is being used you can get more than a "mind-reader's guess" type of response here.
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
modified 16-Oct-13 22:12pm.
|
|
|
|
|
|
If your list is almost sorted, you could use your own sort alogrithm.
If your run some tests[^], you will notice bubble sort does fairly well with lists that are almost sorted.
|
|
|
|
|
|
You could use the OrderBy<TSource, TKey>(Func<TSource, TKey>) extension method.
The actual sorting is deffered until result gets enumerated, so the call to OrderBy() itself is fast.
It performs a stable sort, which means that the order of already sorted elements is preserved.
it does not sort the original sequence in-place. Instead, the returned IEnumerable<tsource> returns elements of the original sequence in sorted order.
And you can speed things up a bit with parallel LINQ like:
var result = sourceSequence.AsParallel().OrderBy(item => item.Key);
Gabriel Szabo
|
|
|
|
|
Hi all,
i am trying to develop a simple application to capture image from USB 2.0 PC camera by pressing the phyiscal button on the camera.
i tried the below code. please help me. in the below code need to press button on the windows application to capture image from usb camera where as i need to capture image from physical button present on the camera.
public Form1()
{
InitializeComponent();
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in webcam)
{
comboBox1.Items.Add(VideoCaptureDevice.Name);
}
comboBox1.SelectedIndex = 1;
cam = new VideoCaptureDevice(webcam[comboBox1.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
}
private FilterInfoCollection webcam;
private VideoCaptureDevice cam;
Bitmap bitmap;
void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
bitmap = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = bitmap;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image = bitmap;
}
private void button3_Click(object sender, EventArgs e)
{
if (cam.IsRunning)
{
cam.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap current = (Bitmap)bitmap.Clone();
string filepath = Environment.CurrentDirectory;
string fileName = System.IO.Path.Combine(filepath, @"name.bmp");
current.Save(fileName);
current.Dispose();
}
|
|
|
|
|
The VideoCaptureDevice class does not expose any events; AFAIK there's no code triggered by .NET on a physical push on a button on a device. It's not something that's "standard" available for any webcam.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
@Eddy Vluggen
Thanks for the reply.
any other solution? or sample code to do?
please help me
|
|
|
|
|
You should have to get with the manufacturer of the camera for an SDKto use so you can get at the button on it.
|
|
|
|
|
I need to make a 'bot' style program that will mimic real life user interface. On the fist page I have a login/pass on submit. This step I have conqured:
webBrowser1.Document.GetElementById("ctl00_MainContentArea_sei_form_password").SetAttribute("value", "PASSWORD");
webBrowser1.Document.GetElementById("ctl00_MainContentArea_sei_form_username").SetAttribute("value", "USER");
HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement el in elc)
{
if (el.GetAttribute("type").Equals("submit") && el.GetAttribute("name").Equals("ctl00$MainContentArea$sei_form_submit"))
{
el.InvokeMember("click");
}
}
but now i have to get to 2 a hrefs that are buried deep inside a div tag:(the 2 files marked Roster_Lookups.zip and IDX_Listing_Data)
<div id="ctl00_MainContentArea_sei_download_content_area" class="sei_content_padding"><div class="sei_left_float_small">
<div class="sei_content_bg_gold">
<h2>Data Download User Info</h2>
<div class="sei_content_gold">
<div class="sei_data_font">
<div id="sei_data_user_info"><p> <b>User Name: </b>LOGIN</p>
<p><b>MLS Account: </b>Door County</p>
<p><b>Date Created: </b>6/18/2008 3:14:00 PM</p>
<p align="center"><a href="data_download.aspx?loggout=true">Click Here to Logout</a></p></div>
</div>
</div>
</div>
</div>
<div class="sei_left_float_padding">
<div class="sei_content_bg_blue">
<h2>Data Available For Download</h2>
<div class="sei_content_blue">
<div class="sei_data_font">
<p>The data below is made available to you by your MLS. For data specifications, and general information please contact your MLS office.</p><br>
<p class="sei_require"><b>New Update:</b><br> The IDX_Custom.zip file has been split into 2 zip files. The file named IDX_Listing_Data.zip will contain the listing data. The file named Roster_Lookups.zip will contain the roster and lookup information.</p><br>
<p class="sei_data_file_name"><a href="popdown.asp?file=IDX_Listing_Data.zip" target="download"><img src="images/zip.gif" alt="File" border="0" align="absmiddle">IDX_Listing_Data.zip</a></p><div class="sei_data_file_update">File Last Updated: 10/15/2013 3:49:59 AM</div><p></p><p class="sei_data_file_name"><a href="popdown.asp?file=Roster_Lookups.zip" target="download"><img src="images/zip.gif" alt="File" border="0" align="absmiddle">Roster_Lookups.zip</a></p><div class="sei_data_file_update">File Last Updated: 10/15/2013 3:50:00 AM</div><p></p>
</div>
</div>
</div>
</div>
<div class="sei_clear"></div>
</div>
This is set to not allow a cookie post/response set, so i need to try to get some kind of mouse move, tab move, and click value to associate the hyperlinks that are buried inside of that flash element.
All ideas are welcome!
|
|
|
|
|
What do you want to achieve: a tool for testing a website or a robot which downloads some files from some web location?
And neither of them would use "mouse move" etc., they look for the element (here: href), get the necessary data (i.e. URL), and perform the correct operation (i.e. download) on them.
|
|
|
|
|
I have data in dataset or datatable I need to design table dynamically with alignment, table column as background colour using console application.Please help me out this query.
Regards,
Abhi
|
|
|
|
|
Your question is not at all clear, try rewording it.
Veni, vidi, abiit domum
|
|
|
|
|
Doesn't seem to be much info on them. Main goal is, given an array of polygon points, I want to extract / copy that region of the CAD drawing and save it out to a separate file. Preferably a TIFF. This is for work, so if I need to purchase a library, that is definitely an option. This is for a throw away / in-house util, so the quickest / easiest way would be best. Performance is an issue as this will be used in a big production run.
EDIT: CAD files will be pretty large... I don't think I want to use a command line AutoCad -> TIFF converter and then load the TIFF file... although that'd probably work, performance would be the issue as the large CAD file would have to be loaded, and then I'd have to load the TIFF file again. Twice the work.
|
|
|
|
|
Start by reading this[^] thread.
SledgeHammer01 wrote: Twice the work. Twice the work for the computer. How much weeks are you prepared to spend optimizing this task? And what would the gain be in terms of time saved, divided by the money spent during development?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Seen it. Not very useful. Yes, twice the work for the computer. Runtime is important. If it takes 5 seconds to load the file, 5 seconds to convert it in memory, 5 seconds to write it out, then another 5 seconds to load the TIFF version, that is not a good implementation for us. 20 seconds overhead is not a big deal for a single run, but when you are talking about 10,000 runs, that 20 seconds becomes 200,000 seconds = 55 hours. 100,000 runs now takes an extra 23 *DAYS*.
|
|
|
|
|
SledgeHammer01 wrote: 100,000 runs now takes an extra 23 *DAYS*. Do they have to be processed sequentially by the same machine, or would it be allowed to divide and conquer?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It has been a long time since I worked with AutoCad (2000 version), but couldn't you do this from within AutoCad by creating a layout with a polygon viewport and then plotting that to a TIFF print driver?
|
|
|
|
|
This guy[^] on the codeproject has developed a commercial program for reading CAD files, and I think there are some articles on the very toping on this site.
|
|
|
|
|
Hi,
I have a field in the database, which has 3 static values tied to it. Is there a way to define in the .dbml file some static values?
Meaning there is field called "CustomerType" in the database. CutomerType has only 3 values in dropdown, Patient, Physician, Nurse. Is there a way to tie this column to static values?
Thanks!!
|
|
|
|
|
What do you mean by "static" here? AFAIK, each record would be made "static" by it's primary key.
You mean that the list doesn't change? Then why not hardcode it? Would it hurt much to assume that at one point someone will add a "nurse chief"?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
This project is set up as a Dynamic Data Scaffolding project. Something that is new to me.
I am trying to insert an item, but it should have a dropdown list of the items.
|
|
|
|
|