Inside the HybridDictionary

When picking a data structure to store key/value pairs and the size is unknown the HybridDictionary object (System.Collections.Specialized) is a great tool for the job.  The data structure will internally use a ListDictionary while the count is <= 10 and will convert to using a Hashtable afterwards.  If the starting item count is greater than 10, the HybridDictionary will start out with the Hashtable to reduce the overhead generated by the conversion.

A ListDictionary uses an single linked list data structure for implementation so the Item, Add, Remove, and Contain operations are all in linear time.

The Hashtable works off the Object.GetHashCode method for storage.  For each entry, a key, value, and a hashcode is stored.  The entry is placed into a bucket based on this hashcode.  Each time a item is added to the Hashtable, an actual load factor is computed  and is compared to the specified load factor.  The default load factor of 1.0 can be changed during the Hashtable creation, but must be between 0.10 and 1.0.  The load factor is directly related to the probability that a bucket will contain more than one entry.  The lower the value, the less chance of a collision but the trade-off is memory consumption.  Then the actual equals the specified load factor, the Hashtable is reallocated to contain the smallest prime number larger than twice the current number of hashtable buckets.  Dan Mabbutt has some interesting benchmarks regarding the load factor. 

Customized hashing can be achieved by overriding the Object.GetHashCode, and Object.GetEquals methods.  Using the IEqualityComparer interface will enforce these methods.

The operations for the Hashtable are all in constant time on average with the exceptions of reallocation, hash collisions, and multiple items in a bucket.  The Hashtable will automatically rehash collisions.

For a hash table review visit Wikipedia.

Remember that all key objects must be immutable!


Posted by: kjsteuer
Posted on: 3/31/2008 at 12:12 PM
Tags: ,
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (3) | Post RSSRSS comment feed

applicationSettings vs. appSettings

applicationSettings was introduced into the .Net 2.0 Framework.  This is not the same as appSettings which most developers used 1.1, but what is the difference?

Application settings give us more control and most important, intelliscence.  To create an application setting simply view your projects properties and select Settings.

applicationSettings

Here you can see that there are more parameters than the standard appSettings.  Additionally there are the fields Type, and Scope.  This Type is used for intelliscence in Visual Studio.

Within the config file, the following section is added:

    <userSettings>
        <applicationSettings_vs_appSettings.My.MySettings>
            <setting name="MySetting" serializeAs="String">
                <value>MySettingString</value>
            </setting>
        </applicationSettings_vs_appSettings.My.MySettings>
    </userSettings> 

This allows us to use intelliscence in our application now.

        Console.WriteLine(My.Settings.MySetting)

This can be very useful and it is strongly typed so it is faster.  However, applicationSettings are only in console applications, forms applications and web applications, they do not exist in websites.  For the websites you must resort to the old appSettings standard.

To set the setting to a new value simply, set the property and save the settings.

        Console.WriteLine(My.Settings.MySetting) 'MySettingString
        My.Settings.MySetting = "new setting"
        My.Settings.Save()
        Console.WriteLine(My.Settings.MySetting) 'new setting

applicationSettings2

I am not sure why this doesn't exist in the websites.  I came across this when I was getting the error: Configuration system failed to initialize from trying to use the Configuration manager versus using My.Settings.


Posted by: kjsteuer
Posted on: 3/27/2008 at 4:45 PM
Tags: ,
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (3) | Post RSSRSS comment feed

Online Computer Science Materials

I remember when MIT came out with MITOPENCOURSEWARE.  I thought this would fuel other online training programs, but nothing ever came of it. 

Google is taking another stab at it with Google Code University.  They offer courses in AJAX Programming, Distributed Systems, Web Security, and Languages.  The courses are provided by Google and different Universities.  Outside the lectures are different tools and a nice CS Curriculum Search.  The CS Curriculum Search is specific to materials posted by different CS Departments.

It is another great step for online education.  This is very different from Microsoft's great Webcasts because MS Webcasts target only their products.  MIT's and Google's online training target the fundamentals of Computer Science which is what we need.


Posted by: kjsteuer
Posted on: 3/20/2008 at 12:59 PM
Tags:
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Alltel HTC Touch Internet Connection Sharing

I am leaving on vacation in two days so today I set out to use the internet connection sharing feature of the HTC Touch. It's simple and quick!

1. Navigate to The Comm Manager
  • Start -> Settings -> Connections -> Comm Manager

2. Click on Internet Sharing

  • Select PC connection, for me it is Bluetooth PAN. I suppose this also works via USB.
  • Select Network Connection to share, mine is Altel Wireless

3. Connect devices via searching from PC - HTC83

  • This was a bit dificult because I did not know the passcodes so I tried 0000 (zeros) and viola!

4. Each device will display a connection confirmation and display the number of services the other device offers.

  • Select the Network Access point on the PC.

5. Open up a Web Browser and start surfing.

After the devices are synced the first time, simply use the shortcut on the PC in My Bluetooth Places for the Network Access Point.

Posted by: kjsteuer
Posted on: 3/6/2008 at 3:47 PM
Tags:
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Project Update

I haven't blogged about the project for a while but I am changing the context of this blog. This blog will be about technology in general as I encounter and learn new concepts.

Posted by: kjsteuer
Posted on: 3/6/2008 at 3:44 PM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed