[sword-devel] Fastest way of counting verses

Troy A. Griffitts scribe at crosswire.org
Thu Mar 12 06:19:56 MST 2009


Manfred,

Are you specifically asking about how to obtain the ordinal count of a 
traversable SWKey?

If so, the official answer is, "you can't without counting yourself". 
SWKey's which return true for isTraversible() don't contractually offer 
their set count.  This is fairly common with optimized object containers 
who's set count is not easily derived (think of linked lists).

Having said this, SWKey offers a bookmarking facility with long 
SWKey::Index(), SWKey::Index(long).

The longs can _usually_ be used to practically bound a 'range'.

e.g.

VerseKey *parser = (VerseKey *)kjv->getKey();
ListKey keySet = parser->ParseVerseList("matt-jn", parser, true);

keySet = TOP;
long start = keySet.Index();
keySet = BOTTOM;
long end = keySet.Index();

progressBar.setStart(start);
progressBar.setEnd(end);


for (keySet = TOP; !keySet.Error(); keySet++) {
	progressBar.setValue(keySet.Index());
	// process text here...
}


// Having said this, a few points:

obvious fail case: "gen; rev22:21"

true ordinal count:
long i = 0; for (keySet = TOP; !keySet.Error(); keySet++) i++;

finally, processing a set of display data should really not take humanly 
noticeable times on even old desktop computers (or even reasonably 
recent mobile devices).  We've actually, recently been trying to 
optimize things on mobile devices for SwordReader and as we continue to 
make improvements for these devices you should see improvements on all 
platforms.  Please let us know with a snippet of code which demonstrates 
an iteration which takes any noticeable time to complete.

	-Troy.





Manfred Bergmann wrote:
> Hi.
> 
> Another APi question:
> 
> In order to show a progress indicator to not bore the user when the 
> cursor ball spins and a text pull takes a little longer I want to know 
> how many verses need to be pulled before actually doing it.
> This can be for any reference the user enters, "gen" or "gen 1,6,9" or 
> anything like that.
> What is the fastest way to do that?
> 
> 
> Regards,
> Manfred
> 
> 
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page




More information about the sword-devel mailing list