Afficher un message
Vieux 06/07/2008, 21h54   #22
Jim Langston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

"xyz" <lavanyareddy.p@gmail.com> wrote in message
news:20e412b2-8666-40af-b3ae-44b543da933b@b1g2000hsg.googlegroups.com...
On Jul 4, 11:44 am, James Kanze <james.ka...@gmail.com> wrote:
> On Jul 3, 1:30 pm, "Duane Hebert" <s...@flarn2.com> wrote:
>
> > "James Kanze" <james.ka...@gmail.com> wrote in message
> >news:40e49767-091e-406d-92c0-9d0f42f24a08@b1g2000hsg.googlegroups.com...
> > >With a good hashing function, look up in a hash table is O(1).
> > >With something like 2 million entries, the difference between
> > >O(ln n) and O(1) can be significant. (In my own tests, hash
> > >tables beat std::map or a sorted factor by a ratio of two to one
> > >for 1200 entries, and almost five to one for a million entries.)

> > True but he's saying that his code is bottlenecked in the
> > search but then if the object isn't found, he's pushing it
> > into a vector. It's not clear if it's the same vector.

>
> It's not clear at all what he does if he don't find the element.
> (At one point, he says something about a "new" vector, but I'm
> not sure what he's doing with it.)
>
> > If it is and he needs to keep it sorted, inserting in the
> > middle of the vector may offset any value from the hash table.

>
> I'm afraid I don't understand. The hash table contains the
> elements he's comparing against. Depending on what he's doing
> he may want to insert the element he didn't find into the hash
> table, or he may not. There's been no indication of having to
> keep any sort of order (or at least, I didn't see it).
>
> --
> James Kanze (GABI Software) email:james.ka...@gmail.com
> Conseils en informatique orientée objet/
> Beratung in objektorientierter Datenverarbeitung
> 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


-------

> I already cleared about this point in the post...
>
> I check every incoming element the vector1...if it matches in one of
> the element in the vector1 I collect the statistics...
> after certain timeout the entreis get deleted...in vector1...the
> timeout for every entry in the vector veries.
> suppose if my entry doesnt match any of the entreis in vector1 i store
> it in other vector for eg namely vector2
> and these entreis i export to other module...and it does something
> with those entries
>
> as i get high timeouts my vectors are very large...so the incoming
> element needs to check all those entries whether it is matched in the
> vector or not..so i asked whether it is better to use vectors or
> maps...
> thats all...thanks everyone...
> hope everyone understand....


Have you followed the thread so far? You should have enough information to
decide which to at least try. Most likely you will want to try a sorted
vector, a hash map/set and see which is better for you. You have not stated
how/when entries would get added to vector1. If entries *never* get added,
the a sorted vector would definately be the way to go. Read your vector1 at
the beginning, sort it. Instead of deleting the entries after timeout,
however, I would probalby mark it as delted somehow (just so I wouldn't have
to resort my vector).

If you add entries to vector1 periodically, then maybe a sorted vector would
still be the way to go, or a binary tree (map/set/hashmap, whatever). It
depends on how often you insert entries, etc... An unsorted vector is
defintely NOT the way to go, however. Worst case scenario.


  Réponse avec citation
 
Page generated in 0,06141 seconds with 9 queries