epitzer / sparsehash

Automatically exported from code.google.com/p/sparsehash
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Patch to allow finding the position of a nonempty_iterator #73

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi!

It's useful when scanning over a table with the nonempty_iterator to be able to 
calculate the current position of the iterator in the table. Simple API:

sparsetable<int> table(100);

// Add things to table

for (sparsetable<int>::nonempty_iterator it=table.nonempty_ 
begin(),ite=table.nonempty_end();it!=ite;++it){
   int pos = table.get_pos(it);
  // Do stuff with pos
}

Attached a patch, plenty of room for optimisation by removing branch perhaps? 
The repetition of bits_in is a bit cumbersome too. Not sure how to place that 
outside of a static function...

Let me know if you what any changes!

Cheers,
Donovan.

Original issue reported on code.google.com by DonovanH...@gmail.com on 10 Jul 2011 at 6:22

Attachments:

GoogleCodeExporter commented 8 years ago
Oops, missed out the tests. Please refer to this attached diff instead.

Original comment by DonovanH...@gmail.com on 10 Jul 2011 at 6:39

Attachments:

GoogleCodeExporter commented 8 years ago
I'm obviously not very good with attachments!

Please use this one (fingers crossed!)

Original comment by DonovanH...@gmail.com on 10 Jul 2011 at 6:42

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the patch!  It looks good to me.  I'll pass it by someone here who 
is good at optimizing to see if they have any recommendations, but I'll look to 
get it into svn-trunk sometime this week.

Original comment by csilv...@gmail.com on 11 Jul 2011 at 10:43

GoogleCodeExporter commented 8 years ago

Original comment by csilv...@gmail.com on 12 Jul 2011 at 12:55

GoogleCodeExporter commented 8 years ago
btw, can you please sign the CLA at
   http://code.google.com/legal/individual-cla-v1.0.html
if you haven't already?  Thanks!

Original comment by csilv...@gmail.com on 12 Jul 2011 at 12:57

GoogleCodeExporter commented 8 years ago
That's done, signed and submitted!

Original comment by DonovanH...@gmail.com on 12 Jul 2011 at 1:18

GoogleCodeExporter commented 8 years ago
Fixed in r76

Original comment by csilv...@gmail.com on 26 Aug 2011 at 1:27