commit 869f7d7a83c46990976796acb77d33b0d641eaa1
Author: dprunier <dominique.prunier@watch4net.com>
Date:   Thu Jan 12 15:58:05 2012

    allow a result set to jump to the next bundle (equivalent to SELECT DISTINCT)

diff --git a/src/bundle.cpp b/src/bundle.cpp
index bf6c179..e6d4cba 100755
--- a/src/bundle.cpp
+++ b/src/bundle.cpp
@@ -2443,6 +2443,23 @@ bool ibis::query::result::next() {
     return ret;
 } // ibis::query::result::next
 
+bool ibis::query::result::nextBundle() {
+    bool ret = false;
+    if (bdl_ == 0)
+	return ret;
+    const uint32_t bsize = bdl_->size();
+    if (bid_ < bsize) {
+	ret = true;
+	lib_ = bdl_->numRowsInBundle(bid_) - 1;
+	++ bid_;
+    }
+    else if (bid_ == bsize) {
+	lib_ = 0;
+	++ bid_;
+    }
+    return ret;
+} // ibis::query::result::nextBundle
+
 void ibis::query::result::reset() {
     bid_ = 0;
     lib_ = 0;
diff --git a/src/bundle.h b/src/bundle.h
index 9e53cf6..16f7095 100644
--- a/src/bundle.h
+++ b/src/bundle.h
@@ -342,6 +342,8 @@ public:
 
     /// Move to the next row/record of results.
     bool next();
+    /// Jump to the next bundle of results.
+    bool nextBundle();
     /// Move the internal pointer back to the beginning.  Must call @c next
     /// to use the first set of results.
     void reset();
diff --git a/src/capi.cpp b/src/capi.cpp
index c8a1384..089301b 100755
--- a/src/capi.cpp
+++ b/src/capi.cpp
@@ -1911,6 +1911,37 @@ fastbit_result_set_next(FastBitResultSetHandle rset) {
 } // fastbit_result_set_next
 
 extern "C" int
+fastbit_result_set_next_bundle(FastBitResultSetHandle rset) {
+    int ierr = -1;
+    try {
+	if (rset == 0)
+	    ierr = -2;
+	else if (rset->results->nextBundle())
+	    ierr = 0;
+    }
+    catch (const std::exception& e) {
+	LOGGER(ibis::gVerbose > 0)
+	    << "Warning -- fastbit_result_set_next_bundle failed to prepare the "
+	    "next row due to exception: " << e.what();
+	ierr = -3;
+    }
+    catch (const char* s) {
+	LOGGER(ibis::gVerbose > 0)
+	    << "Warning -- fastbit_result_set_next_bundle failed to prepare the "
+	    "next row due to a string exception: " << s;
+	ierr = -4;
+    }
+    catch (...) {
+	LOGGER(ibis::gVerbose > 0)
+	    << "Warning -- fastbit_result_set_next_bundle failed to prepare the "
+	    "next row due to a unknown exception";
+	ierr = -5;
+    }
+
+    return ierr;
+} // fastbit_result_set_next_bundle
+
+extern "C" int
 fastbit_result_set_get_int(FastBitResultSetHandle rset,
 			   const char *cname) {
     int ret = INT_MAX;
diff --git a/src/capi.h b/src/capi.h
index 2672764..9f78a69 100644
--- a/src/capi.h
+++ b/src/capi.h
@@ -187,6 +187,8 @@ extern "C" {
 
     ///@brief Returns 0 if there are more results, otherwise returns -1.
     FASTBIT_DLLSPEC int fastbit_result_set_next(FastBitResultSetHandle rset);
+    ///@brief Returns 0 if there are more bundles, otherwise returns -1.
+    FASTBIT_DLLSPEC int fastbit_result_set_next_bundle(FastBitResultSetHandle rset);
     ///@brief Get the value of the named column as an integer.
     FASTBIT_DLLSPEC int
     fastbit_result_set_get_int(FastBitResultSetHandle rset, const char *cname);
