.net - Performance Of Implementation Of IComparer?
Jul 14, 2011
I'm sorting a collection of type "Document" (usually around 100k records). Sorting usually takes around 4-5 seconds, and I'm wondering if there's a way to speed up sorting by modifying my "DocumentComparer" class which implements IComparer(Of Document). Since the Compare() method would be called hundreds of thousands of times, are there any performance improvements that could be made here that I've overlooked?
I created an array sorter to sort arrays like in Win Explorer in a DNN module. As in the answer to a preview question: Sorting an array of folder names like Windows Explorer (Numerically and Alphabetically) - VB.NET
So I've been doing some research on the singleton factory design pattern, and I am wondering if my example implementation is correct (warning I did get carried away creating animals):
I am using structures in my programming and I sort the structure according to a value in the structure using IComparer. How did Microsoft implement the Array.Sort() method? Is there any documentation (references) for this? Is it the same for all types of Sort() in Visual Basic?
This is a simple example for what I want. Dim MyArray(6) As Integer MyArray(0) = 1 MyArray(1) = 45 MyArray(2) = 45 [Code] .....
Array.Sort() will sort this array as: (1 1 1 10 45 45 57)
How does number 1 get sorted? Is it bringing to the end the first one or keeps the old one in the same index? In my original example (before sorting), MyArray(0) = 1 and after sorting MyArray(0) = 1. Is this the same original 1 or this another 1 (the newest one added to the array) moved to that position? In case the MyArray(0) = 1 after sorting should be MyArray(5) = 1 before sorting.
I'm using Visual Studio .Net 2008 on Vista. The goal of my program is to watch a directory, get file information, then sort them by thier date, and produce a updated text file. I can't seem to get my code to generate a list of files sorted by date. The code does produce a general list of files, however presently ordered in the directory. I also tried an alternate way of sorting the files by date by creating a string, removing the date using substring, then comparing the file dates using datetime.parse but it produces a exception error. My first method using the structure follows:
I am trying to create a class implementing the generic IComparer of my own class "Stellungen" (which translates to positions, like on a chess or checkers board).
This is what I got: Private Class comparer(Of Stellung) Implements System.Collections.Generic.IComparer(Of Stellung) Public Function Compare(x As Stellung, y As Stellung) As Integer Implements System.Collections.Generic.IComparer(Of Stellung).Compare End Function End Class
Problem is: inside the function I have no access to any fields of my class. If I start off with x. Intellisense will only give me .Equals, .GetHashCode - the methods you get on a type but not on an instance. Visual Studio 10 also highlights this, in the definition of the function the bits "x as Stellung" and "y as Stellung" are written in light blue, meaning it is a type and not an actual object. How do I access the things I want to compare inside my class?
I'm having trouble implementing an IComparer method. Essentially, I want to compare the properties of two custom objects (the properties are of type integer).dE is a Dictionary(Of String, customObj)prTabIndex is a property of customObj and is of type Integer (these hold true for all examples)After some more searching I found this thread which suggested 3 things: a List approach, utilizing LINQ, and using some C# 3.0 features. I've tried three different ways:...rolling my own IComparer implementation:
Public m As Sub(ByRef d As Dictionary(of String, customObj)) Dim sortedD As New SortedDictionary(Of String, customObj)(d, myCompare) End Sub
[code]....
Note that VS2008 has underlined 'dE.ToDictionary...' (to the end of the line) and giving me two messages depending on where I hover my mouse:
1) "Data type(s) of the type parameter(s) in extension method 'signature' As 'signature defined in 'System.Linq.Enumerable cannot be inferred from these arguments. Specifying the data types explicitly might correct this error. Seen while hovering over "ToDictionary".
2) Nested function does not have the same signature as delegate 'signature'. Seen while hovering over anything after "ToDictionary".
Q1) How far off am I in each of the implementations?
Q2) Which one is the computationally least expensive? Why?
Q3) Which one is the computationally most expensive? Why?
I am working on a general helper class to sort ListView SubItems. I wrote a base class that has much of the code I need. It includes a MustOverride for the Compare method so that the various inherited classes can implment their own comparisons based upon their type. For the value types, I end up with very similar code such as the following, where x and y are ListViewItems: Public Overloads Overrides Function Compare(ByVal x As Object, ByVal y As Object, ByVal sortColumnIndex As Integer, ByVal sortOrder As System.Windows.Forms.SortOrder) As Integer [code]
I am a budding MCTS so I am not a 100% sure of whether I am correct in this instance.I am looking through a windows forms application created by a developer who has left our company some time ago. Within the code I have found a custom form derived from the standard form baseclass which explicity implements IDisposable.The custom form does not call any COM object or do any file IO operations and has only one database call which is closed and disposed off in the method that calls it. However within the code of the form there is the following,[code].....
Looking at this am I right in thinking that this should be removed including the implements IDisposable line at the top of the form since,
1. The listeners collection will go out of scope when the form does as the collection only references listener objects (which do not implement IDisposable).
2. The controls do not explicitly need disposing, since when the form goes out of scope this will be done anyway.
I need to implement the IBindableComponent to the the following code:
Public Class InfragisticsToolStripBindableButton Inherits Infragistics.Win.UltraWinToolbars.ButtonTool Implements IBindableComponent
[CODE]...
1 problem: Warning: event 'Disposed' conflicts with property 'Disposed' in the base class 'DisposableObject' and should be declared 'Shadows'
2 problem: Error: Class 'InfragisticsToolStripBindableButton' must implement 'Property Site As ISite' for interface 'System.ComponentModel.IComponent'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers.
Why should I implement "IComponent" if I implement "IBindableComponent"?
3 problem: How should I override "Dispose", if it's already implemented in the base class, but is not virtual apparently.
After some research, I've decided to use the Liang-Barsky line clipping algorithm in my 2D game. Google did not deliver on any VB.NET implementations of this algorithm but plenty C/++ ones. Therefore, as I have knowledge in C++, decided to port one found on Skytopia over to VB.Net. Unfortunately, it does not work with:
Public Class PhysicsObject Public Function CollideRay(ByVal p0 As Point, ByVal p1 As Point, ByRef clip0 As Point, ByRef clip1 As Point) As Boolean Dim t0 As Double = 0.0 Dim t1 As Double = 1.0
[code]....
However, the CollideRay method fails on its 3rd edge iteration (edge = 3), r < t0, therefore the function returns false.
I can't use string.Format, I have C style format strings;I can't call the native printf (no P/Invoke);I can't use http://www.codeproject.com/KB/printing/PrintfImplementationinCS.aspx because of the license, I need something GPL-compatible.Is there a free implementation of printf/sprintf for the .net framework? Other than the above link, I couldn't find anything.
I cooked up a sprintf function that supports basic format strings, you can find it here: [URL].. I'll try to make it a complete implementation if I can.
I need to use some functions from a DLL written in C++. Problem is when I try to use those functions in VB (Visual Studio). The only way I get to pass the debugger without errors is if I use the VariantType type, but I get all screwed up values. Can anyone tell me how can I "translate" the use of char [6] into VB from C++? My problem when Implementing is with the variable INFO, the content comes back after execution with errors..This is the original code from the DLL Manual:
Code: Int Get_Info(A Handle, char *IPAddr, InfoType *Info) where the parameters: A [IN] Handle. IPAddr [IN] IP address
I implemented IDisposable into one of my classes, but don't know if I did it correctly. Can someone tell me what will be cleared from memory and what will remain after calling .Dispose on an instance of this class? [Code]
I am working on an application which uses multiple threads to work on number of tasks and the parent application receives the output of the task,later to be written to files, currently I am using arraylist to append output to, but that happens to be slow when removing items from queue.I was thinking to convert arraylist part to linkedlist for optimized reads and clears,if linkedList Implementation of .Net is threadsafe or even using arraylist was threadsafe?
The middleware that manages talk between the mainframe and our app is blowing up randomly. It's a "such and such attempted to read/write protected memory..." error.The vendor is saying there we must be running some unmanaged code (I feel they're trying to worm out of it). I know VB's entirely managed, but does anyone know about the server portion of AJAX? Is there any server side javascript stuff that occurs before it actually gets into the .NET framework?
I have been reading about design patterns and application architecture and im told that I should program to an interface instead of implementation. This i understand. So I figured I would start with something small. Never programmed with an interface before. So I want to create an encryption program that will allow the user to select which method to encrypt it with, AES, DPAPI, etc. I started designing the Interface but I am unsure if I am doing this right. [Code] Also, when it comes to the DPAPI implementation, how is the client supposed to supply the Protection Scope? I didn't think this should be in the interface as it only applys to the DPAPI.
I need to create a monitoring mechanism using SNMP (in .Net). I think we'll be using an nsoftware component to handle most of the work. It appears we must use 'traps' to communicate from the agent to the server. We'll have a number of different traps and various information detailing each trap. What is the best way to implement custom traps? That is, what is the best way to not only send a trap, but also send the information describing the trap to our 'snmp manager'? I think this is done through "variable bindings". To use "variable bindings" do we need to create our own "enterprise number" and use an "enterpriseSpecific" trap? Should we implement our own, custom MIBs or can we just send the data we need with the trap (via variable bindings)?
In Flash 10 there are methods that require that they are triggered from user-initiated actions like button click, keyboard up/down keys, etc.Is it possible to implement this behaviour in .NET? For example, if we have this subroutine:
void SomeMethod() { // Here some stuff }
how to check inside it whether the method was called from a mouse click event handler?Also we can think of this methods like the protected functions in World of Warcraft.
EDIT: Looks like this behaviour is implemented in Silverlight — we can popup file dialogs (open, save) ONLY by mouse click or other user-initiated action, otherwise a SecurityException will be thrown. I want to achieve this bevaviour but in my case it's not a file dialog but our own methods.
just wondering if we could change the implementation functino of IDisposable.Dispose to a private. because the default i've got something like this:
[Code]...
Protected Overridable Sub Dispose(ByVal disposing As Boolean) or could i take away the the Protected Overridable and replace it with a Private access modifier?
This may seem like an obvious answer, but I can't seem to find an answer. I have this code in VB.NET[code]...
The problem with this is that in C#, it would seem you have to name the function the same as the interface function you are implementing. How can I call this method EncryptionVB instead of Encryption, but still implement the Encryption property?
I implemented Hooks in windows form. I want to set the tab order according to my order But it is taking arbitrary . can you help how to set tab order in windows form in hook