Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

opt(iterator): Optimise the iterator and introduce range iterators #19

Merged
merged 14 commits into from
Aug 16, 2021

Conversation

ahsanbarkati
Copy link
Contributor

@ahsanbarkati ahsanbarkati commented Aug 16, 2021

This PR improves the iterator by doing in-place iteration. It also introduces range iterators.

This change is Reviewable

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. But, the code is hard to follow. Add comments / improve the variable names, perhaps.

I'll review it once again after that.

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ahsanbarkati)


iterator.go, line 71 at r1 (raw file):

	}
	key := it.keys[2*it.kidx]
	off := it.keys[2*it.kidx+1]

Add comments. This code isn't the easiest to follow.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 5 unresolved discussions (waiting on @ahsanbarkati and @manishrjain)


iterator.go, line 31 at r2 (raw file):

	cidx int

	bmHiIdx int // the index of current uint16 in the bitmap container, which is a list of uint16s

why not bitmapIdx? What does Hi imply? Is there a corresponding low index?


iterator.go, line 73 at r2 (raw file):

	// it.keys is a list of the form [key1, offset1, key2, offset2 ... ]
	// the kidx'th key will be present at index 2*it.kidx and the offset corresponding to it will be
	// ont index after after it.

Can you fix this? ont index after after it

Also, why not just increment it.kidx by 2? Then, you can say
key := it.keys[it.keyIdx]; off := it.keys[it.keyIdx+1]

Easier to read.


iterator.go, line 85 at r2 (raw file):

			return 0
		}
		it.kidx++

it.keyIdx += 2


iterator.go, line 103 at r2 (raw file):

		// A bitmap container is an array of uint16s.
		// If the container is bitmap, go to the index which has a non-zero value.
		for it.bitset == 0 && it.bmHiIdx+1 < len(cont[startIdx:]) {

bmHiIdx

Copy link
Contributor Author

@ahsanbarkati ahsanbarkati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 5 unresolved discussions (waiting on @manishrjain)


iterator.go, line 71 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Add comments. This code isn't the easiest to follow.

Done.


iterator.go, line 31 at r2 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

why not bitmapIdx? What does Hi imply? Is there a corresponding low index?

Done.


iterator.go, line 73 at r2 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Can you fix this? ont index after after it

Also, why not just increment it.kidx by 2? Then, you can say
key := it.keys[it.keyIdx]; off := it.keys[it.keyIdx+1]

Easier to read.

Done.


iterator.go, line 85 at r2 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

it.keyIdx += 2

Done.


iterator.go, line 103 at r2 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

bmHiIdx

Done.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: approved. Feel free to merge.

Reviewed 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ahsanbarkati)

@ahsanbarkati ahsanbarkati merged commit bc614dc into main Aug 16, 2021
@ahsanbarkati ahsanbarkati deleted the ahsan/fast-iterator branch August 16, 2021 19:40
@decentral1se
Copy link

decentral1se commented Oct 26, 2022

@ahsanbarkati Sorry for resurrecting this but I'm doing upgrade work atm and am struggling to understand how to implement a reverse iterator on the latest release. Can I use the new range iterator for this purpose? Or do I need to do a ToArray() and then reverse from there? Thanks in advance!

If handier, I have opened up https://discuss.dgraph.io/t/how-to-implement-a-reverse-roaring-bitmap-iterator-sroar-bitmap-newreverseiterator-went-away/17901 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants