473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Insertion into NameObjectCollectionBase

I've created a collection class that inherits the
NameObjectCollectionBase. I'd like to add a few functions, such as being
able to insert a new item at an indexed or keyed location in the
collection. Is there particularly efficient method of doing this, or
does it really come down to copying the collection (to another
collection) up to insertion point, adding the new item, and copying the
rest.....?
--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #1
3 1475
Sam,

NameObjectCollectionBase's underlying type is a Hashtable, not an ordered
list. So "inserting" an object doesn't really have any meaning. With a
hashtable, items are looked up by key, not by position... so basically you
can either add an item, remove an item, or retrieve an item -- all based on
key.

If you really want an ordered list, you should either derive from
CollectionBase instead, or you'll have to keep position information manually
(by, for example, wrapping the inserted items in a class that contains a
position member, then updating / checking that member when your collection
is accessed)

"Sam Marrocco" <sa*@twmi.rr.com> wrote in message
news:Vb****************@fe1.columbus.rr.com...
I've created a collection class that inherits the
NameObjectCollectionBase. I'd like to add a few functions, such as being
able to insert a new item at an indexed or keyed location in the
collection. Is there particularly efficient method of doing this, or
does it really come down to copying the collection (to another
collection) up to insertion point, adding the new item, and copying the
rest.....?
--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #2


Philip Rieck wrote:
Sam,

NameObjectCollectionBase's underlying type is a Hashtable, not an ordered


Philip,
Thanks for the suggestion. I did a bit more reading on the collection
classes available, and tried a few things....
The more I looked, the more I learned that the collections classes
provided seem broken into to categories: Those that are index-based
(collection, etc) , and those that are Key-based (dictionary, etc).
Other than the legacy vb6 collection, there doesn't seem to be a single
collection that supports both indices and keys natively. The vb6 legacy
collection served me well (supporting objects, keys & indices) until the
day I needed serialization (which it does not support); hence my journey
here.

As you suggest, I could wrap my objects with another property such as an
index value, and maintain that value along with all changes to the
collection. However, I'm concerned about the amount of time it would
take to "ripple" changes through large amounts of those indices when
deleting, inserting, etc. a new value into the collections. Not to
mention that locating items further along in the collection will take
longer than sooner in the collection. My collections can consist of
several thousand objects.

I'm continuing to experiment with this......I look forward to any other
suggestions you might have!

--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #3
If you want absolute indexing, unfortunately you'll always run into speed
problems with updating lots of records - everything "after" an insert will
always have to be updated in some way (moved, index data updated, etc).

If you just want ordered traversal, you can alleviate this by using a linked
list, but accessing this by ordinal ( like "obj = collection(7)") is slower
the farther you get from 0.

You're probably going to need to use two internal collections - one for
index mapping, and one for associating these indexes with keys.
See CodeSmith [http://www.ericjsmith.net/codesmith/] for a good collection
class generation tool.

"Sam Marrocco" <sa*@twmi.rr.com> wrote in message
news:b2****************@fe1.columbus.rr.com...


Philip Rieck wrote:
Sam,

NameObjectCollectionBase's underlying type is a Hashtable, not an
ordered
Philip,
Thanks for the suggestion. I did a bit more reading on the collection
classes available, and tried a few things....
The more I looked, the more I learned that the collections classes
provided seem broken into to categories: Those that are index-based
(collection, etc) , and those that are Key-based (dictionary, etc).
Other than the legacy vb6 collection, there doesn't seem to be a single
collection that supports both indices and keys natively. The vb6 legacy
collection served me well (supporting objects, keys & indices) until the
day I needed serialization (which it does not support); hence my journey
here.

As you suggest, I could wrap my objects with another property such as an
index value, and maintain that value along with all changes to the
collection. However, I'm concerned about the amount of time it would
take to "ripple" changes through large amounts of those indices when
deleting, inserting, etc. a new value into the collections. Not to
mention that locating items further along in the collection will take
longer than sooner in the collection. My collections can consist of
several thousand objects.

I'm continuing to experiment with this......I look forward to any other
suggestions you might have!

--
================================================== ================
Sam J. Marrocco
Sr. Visual Effects Artist/R&D
Travelling Pictures/GTN
Inferno, Flame, Maya, All that cool stuff!
"The fact that no one understands you doesn't make you an artist."
================================================== ================

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Billy Jacobs | last post by:
I am getting an error saying: Public Method BaseGet not found on Type 'clsRunCollection'. The error occurs on the call to Public Property Run. If I change the parameter to an integer it works...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
1
by: Rein Petersen | last post by:
Hi Everyone! I hope someone may have experience serializing a NameObjectCollectionBase (System.Collections.Specialized) and can advise me as to why I receive this error (below) when I try to...
3
by: William Stacey [MVP] | last post by:
What is the deal with NameObjectCollectionBase? It allows duplication keys to be added to the hashtable using System; using System.Collections; using System.Collections.Specialized; ...
1
by: Mark Overstreet | last post by:
Hi, I have several custom collections that inherit from System.Collections.Specialized.NameObjectCollectionBase and I want to serialize and deserialize with the XMLSerializer object. This works...
2
by: Mark Overstreet | last post by:
I am writing custom collections for my business objects but I need support for the foreach construct. I also need key support so I am inheriting from NameObjectCollectionBase. I need to support...
1
by: V. | last post by:
Hi, I need to sort the object System.Collections.Specialized.NameObjectCollectionBase based on one property of the special object. Is there an easy way to do this? Thanks Vicky
2
by: Sam Marrocco | last post by:
I've constructed a class that inherits the NameObjectCollectionBase class. All works well, but I'd like to shadow the GetEnumerator method so that it returns an actual value *instead of a...
2
by: Sam Marrocco | last post by:
I've created a collection class that inherits NameObjectCollectionBase (call it MyCollection). MyCollection is declared as serializable, and serializes fine. A cursory glance into the serialized...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.