473,659 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insertion into NameObjectColle ctionBase

I've created a collection class that inherits the
NameObjectColle ctionBase. 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 1492
Sam,

NameObjectColle ctionBase'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.co m> wrote in message
news:Vb******** ********@fe1.co lumbus.rr.com.. .
I've created a collection class that inherits the
NameObjectColle ctionBase. 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,

NameObjectColle ctionBase'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.co m> wrote in message
news:b2******** ********@fe1.co lumbus.rr.com.. .


Philip Rieck wrote:
Sam,

NameObjectColle ctionBase'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
1817
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 but I need to retrieve the object based on it's key. The following is my class:
20
3858
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 a named namespace namespace foo { class Foo
1
2206
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 serialize my instance: System.InvalidOperationException: You must implement a default accessor on System.Collections.Specialized.NameObjectCollectionBase because it inherits from ICollection.
3
4388
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; namespace ns { /// <summary>
1
3424
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 great but my problem is that when the deserialization occurs, it uses the default add method to add objects to the collection without adding the keys. My question is this. Is there any way to use the XMLSerializer object to deserialize and...
2
1983
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 foreach something like e.g. foreach (HostSystem hs in myHost.Systems) Unfortunately the builtin support for foreach only returns the keys of the collection. Anyone have an sample code on how to accomplish this with each of my custom...
1
1377
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
1558
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 DictionaryEntry*. I've gotten strange errors when attempting to override GetEnumerator, such as 'GetEnumerator() cannot override 'Public Overridable NotOverridable Function GetEnumerator() because it is declared NotOverridable......yes, it actually...
2
1670
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 data seems to contain everything in MyCollection and it's base class data, but when I attempt to deserialize it, I get errors about not being able to find the deserialization constructor. Is something not being "passed through" from the inherited...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.