← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/85588

Optimized and cleaned up SimpleTempSeq implementation and its usage.
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/85588
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/context/dynamic_context.cpp'
--- src/context/dynamic_context.cpp	2011-11-09 05:42:08 +0000
+++ src/context/dynamic_context.cpp	2011-12-14 03:25:21 +0000
@@ -313,9 +313,7 @@
   // the variable itself, and the current value of the variable is overwriten
   // here by this temp sequence. TODO: use lazy eval if we know the the 
   // assignment expression does not reference the variable itself.
-  store::TempSeq_t seq = GENV_STORE.createTempSeq(valueIter, 
-                                                  false, // no copy
-                                                  false); // no lazy eval
+  store::TempSeq_t seq = GENV_STORE.createTempSeq(valueIter, false); // no lazy eval
 
   valueIter->close();
 

=== modified file 'src/functions/func_sequences_impl.cpp'
--- src/functions/func_sequences_impl.cpp	2011-12-01 11:02:25 +0000
+++ src/functions/func_sequences_impl.cpp	2011-12-14 03:25:21 +0000
@@ -261,15 +261,28 @@
   {
     xs_double dpos = static_cast<const const_expr*>(posExpr)->
                       get_val()->getDoubleValue().round();
-    long pos = static_cast<long>(dpos.getNumber());
+    xs_integer ipos(dpos.getNumber());
 
     xs_double dlen = static_cast<const const_expr*>(lenExpr)->
                       get_val()->getDoubleValue().round();
-    long len = static_cast<long>(dlen.getNumber());
+    xs_integer ilen(dlen.getNumber());
+
+    xs_long pos;
+    xs_long len;
+
+    try
+    {
+      pos = to_xs_long(ipos);
+      len = to_xs_long(ilen);
+    }
+    catch (std::range_error&)
+    {
+      goto done;
+    }
 
     const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);
 
-    ulong numSteps = pathExpr->numSteps();
+    csize numSteps = pathExpr->numSteps();
 
     if (pos > 0 && len == 1 && numSteps == 2)
     {
@@ -281,6 +294,7 @@
     }
   }
 
+ done:
   return new FnSubsequenceIterator(aSctx, aLoc, aArgs);
 }
 
@@ -319,15 +333,22 @@
       lenExpr != NULL &&
       lenExpr->get_expr_kind() == const_expr_kind)
   {
-    xs_long pos = static_cast<const const_expr*>(posExpr)->
-                      get_val()->getLongValue();
+    xs_long pos;
+    xs_long len;
 
-    xs_long len = static_cast<const const_expr*>(lenExpr)->
-                      get_val()->getLongValue();
+    try
+    {
+      pos = static_cast<const const_expr*>(posExpr)->get_val()->getLongValue();
+      len = static_cast<const const_expr*>(lenExpr)->get_val()->getLongValue();
+    }
+    catch (std::range_error&)
+    {
+      goto done;
+    }
 
     const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);
 
-    ulong numSteps = pathExpr->numSteps();
+    csize numSteps = pathExpr->numSteps();
 
     if (pos > 0 && len == 1 && numSteps == 2)
     {
@@ -367,6 +388,7 @@
     }
   }
 
+ done:
   return new SubsequenceIntIterator(aSctx, aLoc, aArgs);
 }
 
@@ -402,20 +424,31 @@
   if (posExpr->get_expr_kind() == const_expr_kind)
   {
     store::Item* posItem = static_cast<const const_expr*>(posExpr)->get_val();
-    xs_long pos = posItem->getLongValue();
+
+    xs_integer pos = posItem->getIntegerValue();;
 
     if (inputExpr->get_expr_kind() == relpath_expr_kind)
     {
       const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);
 
-      ulong numSteps = pathExpr->numSteps();
+      csize numSteps = pathExpr->numSteps();
 
-      if (pos > 0 && numSteps == 2)
+      if (pos > Integer(0) && numSteps == 2)
       {
+        xs_long pos2;
+        try
+        {
+          pos2 = posItem->getLongValue();
+        }
+        catch (std::range_error&)
+        {
+          goto done;
+        }
+
         AxisIteratorHelper* input = dynamic_cast<AxisIteratorHelper*>(aArgs[0].getp());
         assert(input != NULL);
 
-        if (input->setTargetPos(pos-1))
+        if (input->setTargetPos(pos2 - 1))
           return aArgs[0];
       }
     }
@@ -457,6 +490,7 @@
       return aArgs[0];
   }
 
+ done:
   return new SequencePointAccessIterator(aSctx, aLoc, aArgs);
 }
 

=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
--- src/runtime/booleans/BooleanImpl.cpp	2011-08-08 17:46:14 +0000
+++ src/runtime/booleans/BooleanImpl.cpp	2011-12-14 03:25:21 +0000
@@ -16,6 +16,7 @@
 #include "stdafx.h"
 
 #include "diagnostics/xquery_diagnostics.h"
+#include "diagnostics/util_macros.h"
 
 #include "zorbatypes/collation_manager.h"
 #include "zorbatypes/datetime.h"
@@ -324,7 +325,7 @@
 ********************************************************************************/
 bool CompareIterator::nextImpl(store::Item_t& result, PlanState& planState) const
 {
-  store::Item_t lItem0, lItem1, tItem0, tItem1;
+  store::Item_t item0, item1, tItem0, tItem1;
   bool c0Done = false, c1Done = false, done = false, found = false;
   std::vector<store::Item_t> seq0;
   std::vector<store::Item_t> seq1;
@@ -335,34 +336,34 @@
 
   if (theIsGeneralComparison)
   {
-    if (consumeNext(lItem0, theChild0.getp(), planState))
+    if (consumeNext(item0, theChild0.getp(), planState))
     {
       if (consumeNext(tItem0, theChild0.getp(), planState))
       {
-        seq0.push_back(lItem0);
+        seq0.push_back(item0);
         seq0.push_back(tItem0);
       }
       else
       {
         c0Done = true;
-        if (consumeNext(lItem1, theChild1.getp(), planState))
+        if (consumeNext(item1, theChild1.getp(), planState))
         {
           if (consumeNext(tItem1, theChild1.getp(), planState))
           {
-            seq0.push_back(lItem0);
-            seq1.push_back(lItem1);
+            seq0.push_back(item0);
+            seq1.push_back(item1);
             seq1.push_back(tItem1);
           }
           else
           {
             c1Done = true;
-            found = CompareIterator::generalComparison(loc,
-                                                       lItem0,
-                                                       lItem1,
-                                                       theCompType,
-                                                       theTypeManager,
-                                                       theTimezone,
-                                                       theCollation);
+            found = generalComparison(loc,
+                                      item0,
+                                      item1,
+                                      theCompType,
+                                      theTypeManager,
+                                      theTimezone,
+                                      theCollation);
             done = true;
           }
         }
@@ -383,77 +384,75 @@
 
     if (!done)
     {
-      store::Iterator_t lIter0;
-      store::Iterator_t lIter1;
+      store::Iterator_t ite0;
+      store::Iterator_t ite1;
       tSeq0 = GENV_STORE.createTempSeq(seq0);
       tSeq1 = GENV_STORE.createTempSeq(seq1);
 
       if (!c0Done)
       {
-        lIter0 = new PlanIteratorWrapper(theChild0, planState);
-        tSeq0->append(lIter0, false);
+        ite0 = new PlanIteratorWrapper(theChild0, planState);
+        tSeq0->append(ite0);
       }
 
       if (!c1Done)
       {
-        lIter1 = new PlanIteratorWrapper(theChild1, planState);
-        tSeq1->append(lIter1, false);
+        ite1 = new PlanIteratorWrapper(theChild1, planState);
+        tSeq1->append(ite1);
       }
 
-      ulong i0 = 1;
-      while(!found && tSeq0->containsItem(i0))
+      ite0 = tSeq0->getIterator();
+      ite1 = tSeq1->getIterator();
+      ite0->open();
+      ite1->open();
+
+      while (!found && ite0->next(item0))
       {
-        ulong i1 = 1;
-        while(!found && tSeq1->containsItem(i1))
+        while (!found && ite1->next(item1))
         {
-          store::Item_t item0;
-          store::Item_t item1;
-          tSeq0->getItem(i0, item0);
-          tSeq1->getItem(i1, item1);
-          if (CompareIterator::generalComparison(loc,
-                                                 item0,
-                                                 item1,
-                                                 theCompType,
-                                                 theTypeManager,
-                                                 theTimezone,
-                                                 theCollation))
+          store::Item_t tmp = item0;
+
+          if (generalComparison(loc,
+                                tmp,
+                                item1,
+                                theCompType,
+                                theTypeManager,
+                                theTimezone,
+                                theCollation))
           {
             found = true;
+            break;
           }
-          ++i1;
         }
-        ++i0;
+
+        ite1->reset();
       }
     }
 
-    STACK_PUSH ( GENV_ITEMFACTORY->createBoolean ( result, found ), state );
-
+    STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, found), state);
   }
   else
   {
     // value comparison
-    if (consumeNext(lItem0, theChild0.getp(), planState) &&
-        consumeNext(lItem1, theChild1.getp(), planState))
+    if (consumeNext(item0, theChild0.getp(), planState) &&
+        consumeNext(item1, theChild1.getp(), planState))
     {
       STACK_PUSH(GENV_ITEMFACTORY->
                  createBoolean(result,
                                CompareIterator::valueComparison(loc,
-                                                                lItem0,
-                                                                lItem1,
+                                                                item0,
+                                                                item1,
                                                                 theCompType,
                                                                 theTypeManager,
                                                                 theTimezone,
                                                                 theCollation)),
                  state);
 
-      if (consumeNext(lItem0, theChild0.getp(), planState) ||
-          consumeNext(lItem1, theChild1.getp(), planState))
+      if (consumeNext(item0, theChild0.getp(), planState) ||
+          consumeNext(item1, theChild1.getp(), planState))
       {
-        throw XQUERY_EXCEPTION(
-          err::XPTY0004,
-          ERROR_PARAMS( ZED( NoSeqInValueComp ) ),
-          ERROR_LOC( loc )
-        );
+        RAISE_ERROR(err::XPTY0004, loc,
+        ERROR_PARAMS(ZED(NoSeqInValueComp)));
       }
     }
   }
@@ -1022,7 +1021,9 @@
 
 
 template<TypeConstants::atomic_type_code_t ATC>
-bool TypedValueCompareIterator<ATC>::nextImpl(store::Item_t& result, PlanState& planState) const
+bool TypedValueCompareIterator<ATC>::nextImpl(
+    store::Item_t& result,
+    PlanState& planState) const
 {
   store::Item_t lItem0, lItem1;
   bool bRes;

=== modified file 'src/runtime/core/flwor_iterator.cpp'
--- src/runtime/core/flwor_iterator.cpp	2011-11-22 13:42:18 +0000
+++ src/runtime/core/flwor_iterator.cpp	2011-12-14 03:25:21 +0000
@@ -1237,7 +1237,7 @@
     }
 
     store::TempSeq_t tmpSeq = iterState->theTempSeqs[varNo].getp();
-    tmpSeq->init(iterState->theTempSeqIters[varNo], false);
+    tmpSeq->init(iterState->theTempSeqIters[varNo]);
 
     std::vector<PlanIter_t>::const_iterator viter = flc.theVarRefs.begin();
     std::vector<PlanIter_t>::const_iterator end = flc.theVarRefs.end();
@@ -1420,7 +1420,7 @@
   sortTable[numTuples].theDataPos = numTuples;
 
   store::Iterator_t iterWrapper = new PlanIteratorWrapper(theReturnClause, planState);
-  store::TempSeq_t resultSeq = GENV_STORE.createTempSeq(iterWrapper, false, false);
+  store::TempSeq_t resultSeq = GENV_STORE.createTempSeq(iterWrapper, false);
   store::Iterator_t resultIter = resultSeq->getIterator();
 
   resultTable[numTuples].transfer(resultIter);
@@ -1503,9 +1503,9 @@
     for (csize i = 0; i < numNonGroupingSpecs; ++i)
     {
       store::Iterator_t iterWrapper = 
-      new PlanIteratorWrapper(nongroupingSpecs[i].theInput,
-                                                              planState);
-      (*nongroupVarSequences)[i]->append(iterWrapper, false);
+      new PlanIteratorWrapper(nongroupingSpecs[i].theInput, planState);
+
+      (*nongroupVarSequences)[i]->append(iterWrapper);
 
       nongroupingSpecs[i].reset(planState);
     }
@@ -1521,7 +1521,7 @@
       store::Iterator_t iterWrapper = 
       new PlanIteratorWrapper(nongroupingSpecs[i].theInput, planState);
 
-      store::TempSeq_t result = GENV_STORE.createTempSeq(iterWrapper, false, false);
+      store::TempSeq_t result = GENV_STORE.createTempSeq(iterWrapper, false);
 
       nongroupVarSequences->push_back(result);
 

=== modified file 'src/runtime/core/gflwor/common.h'
--- src/runtime/core/gflwor/common.h	2011-10-22 15:44:45 +0000
+++ src/runtime/core/gflwor/common.h	2011-12-14 03:25:21 +0000
@@ -418,7 +418,7 @@
     const bool aLazyEval)
 {
   store::Iterator_t iterWrapper = new PlanIteratorWrapper(aInput, aPlanState);
-  aTempSeqResult = GENV_STORE.createTempSeq(iterWrapper, false, aLazyEval);
+  aTempSeqResult = GENV_STORE.createTempSeq(iterWrapper, aLazyEval);
 }
   
 

=== modified file 'src/runtime/core/gflwor/groupby_iterator.cpp'
--- src/runtime/core/gflwor/groupby_iterator.cpp	2011-10-22 15:44:45 +0000
+++ src/runtime/core/gflwor/groupby_iterator.cpp	2011-12-14 03:25:21 +0000
@@ -437,7 +437,7 @@
       new PlanIteratorWrapper(theNonGroupingSpecs[i].theInput, aPlanState);
 
       // FIXME are those settings right? I think copy is correct 
-      (*nonGroupTuple)[i]->append(iterWrapper, false);
+      (*nonGroupTuple)[i]->append(iterWrapper);
 
       theNonGroupingSpecs[i].theInput->reset(aPlanState);
     }
@@ -454,7 +454,7 @@
       new PlanIteratorWrapper(theNonGroupingSpecs[i].theInput, aPlanState);
 
       // FIXME are those settings (no-copy and no-lazy) right? 
-      store::TempSeq_t tempSeq = GENV_STORE.createTempSeq(iterWrapper, false, false); 
+      store::TempSeq_t tempSeq = GENV_STORE.createTempSeq(iterWrapper, false); 
 
       nonGroupTuple->push_back(tempSeq);
 

=== modified file 'src/runtime/core/gflwor/window_iterator.cpp'
--- src/runtime/core/gflwor/window_iterator.cpp	2011-06-14 17:26:33 +0000
+++ src/runtime/core/gflwor/window_iterator.cpp	2011-12-14 03:25:21 +0000
@@ -246,8 +246,8 @@
 
   if (!thePosOuterVars.empty())
   {
-    GENV_ITEMFACTORY->createInteger ( lItem, Integer( aPosition ) );
-    bindVariables ( lItem, thePosOuterVars, aPlanState );
+    GENV_ITEMFACTORY->createInteger(lItem, Integer(aPosition));
+    bindVariables(lItem, thePosOuterVars, aPlanState);
   }
 }
 
@@ -767,9 +767,7 @@
     // Create the temp sequence where to materialize the result of the domain
     // expr (lazily if theLazyEval flag is true).
     iterator = new PlanIteratorWrapper(theInputIter, aPlanState);
-    lState->theDomainSeq = GENV_STORE.createTempSeq(iterator,
-                                                    false,
-                                                    theLazyEval);
+    lState->theDomainSeq = GENV_STORE.createTempSeq(iterator, theLazyEval);
 
     // Its clever to switch quite early to avoid a lot of if-else statements
     if (theWindowType == WindowIterator::SLIDING)

=== modified file 'src/runtime/core/path_iterators.h'
--- src/runtime/core/path_iterators.h	2011-06-14 17:26:33 +0000
+++ src/runtime/core/path_iterators.h	2011-12-14 03:25:21 +0000
@@ -63,7 +63,7 @@
   xqtref_t                     theType;
   bool                         theNilledAllowed;
 
-  xs_long                         theTargetPos;
+  xs_long                      theTargetPos;
  
 public:
   AxisIteratorHelper() 

=== modified file 'src/runtime/core/trycatch.cpp'
--- src/runtime/core/trycatch.cpp	2011-08-09 04:29:06 +0000
+++ src/runtime/core/trycatch.cpp	2011-12-14 03:25:21 +0000
@@ -524,7 +524,7 @@
   try
   {
     lIterator = new PlanIteratorWrapper(theChild, planState);
-    state->theTargetSequence = GENV_STORE.createTempSeq(lIterator, false, false);
+    state->theTargetSequence = GENV_STORE.createTempSeq(lIterator, false);
     state->theTempIterator = state->theTargetSequence->getIterator();
     state->theTempIterator->open();
   }

=== modified file 'src/runtime/core/var_iterators.cpp'
--- src/runtime/core/var_iterators.cpp	2011-09-02 20:43:46 +0000
+++ src/runtime/core/var_iterators.cpp	2011-12-14 03:25:21 +0000
@@ -16,6 +16,7 @@
 #include "stdafx.h"
 
 #include "diagnostics/assert.h"
+#include "diagnostics/util_macros.h"
 
 #include "system/globalenv.h"
 
@@ -109,20 +110,18 @@
         store::Item_t item;
 
         if (! consumeNext(item, theChildren[0], planState))
-          throw XQUERY_EXCEPTION(
-            err::XPTY0004,
-            ERROR_PARAMS( ZED( VarValMustBeSingleItem_2 ), theVarName ),
-            ERROR_LOC( loc )
-          );
+        {
+          RAISE_ERROR(err::XPTY0004, loc,
+          ERROR_PARAMS(ZED(VarValMustBeSingleItem_2), theVarName));
+        }
 
         dctx->set_variable(theVarId, theVarName, loc, item);
 
         if (consumeNext(item, theChildren[0], planState))
-          throw XQUERY_EXCEPTION(
-            err::XPTY0004,
-            ERROR_PARAMS( ZED( VarValMustBeSingleItem_2 ), theVarName ),
-            ERROR_LOC( loc )
-          );
+        {
+          RAISE_ERROR(err::XPTY0004, loc,
+          ERROR_PARAMS(ZED(VarValMustBeSingleItem_2), theVarName));
+        }
       }
       else
       {
@@ -169,11 +168,10 @@
   if (theSingleItem)
   {
     if (! consumeNext(item, theChild, planState))
-      throw XQUERY_EXCEPTION(
-        err::XPTY0004,
-        ERROR_PARAMS( ZED( VarValMustBeSingleItem_2 ), theVarName ),
-        ERROR_LOC( loc )
-      );
+    {
+      RAISE_ERROR(err::XPTY0004, loc,
+      ERROR_PARAMS(ZED(VarValMustBeSingleItem_2), theVarName));
+    }
 
     if (theIsLocal)
       planState.theLocalDynCtx->set_variable(theVarId, theVarName, loc, item);
@@ -181,11 +179,10 @@
       planState.theGlobalDynCtx->set_variable(theVarId, theVarName, loc, item);
 
     if (consumeNext(item, theChild, planState))
-      throw XQUERY_EXCEPTION(
-        err::XPTY0004,
-        ERROR_PARAMS( ZED( VarValMustBeSingleItem_2 ), theVarName ),
-        ERROR_LOC( loc )
-      );
+    {
+      RAISE_ERROR(err::XPTY0004, loc,
+      ERROR_PARAMS(ZED(VarValMustBeSingleItem_2), theVarName));
+    }
   }
   else
   {
@@ -295,9 +292,9 @@
 }
 
 
-bool CtxVarIterator::setTargetPos(xs_long v)
+bool CtxVarIterator::setTargetPos(xs_integer v)
 {
-  if (theTargetPos == 0 && theTargetPosIter == NULL)
+  if (theTargetPos == Integer(0) && theTargetPosIter == NULL)
   {
     theTargetPos = v;
     return true;
@@ -308,7 +305,7 @@
 
 bool CtxVarIterator::setTargetPosIter(const PlanIter_t& v)
 {
-  if (theTargetPos == 0 && theTargetPosIter == NULL)
+  if (theTargetPos == Integer(0) && theTargetPosIter == NULL)
   {
     theTargetPosIter = v;
     return true;
@@ -319,7 +316,7 @@
 
 bool CtxVarIterator::setTargetLenIter(const PlanIter_t& v)
 {
-  if (theTargetPos == 0 && theTargetLenIter == NULL)
+  if (theTargetPos == Integer(0) && theTargetLenIter == NULL)
   {
     theTargetLenIter = v;
     return true;
@@ -398,8 +395,8 @@
   store::Item_t varSingleItem;
   store::Item_t posItem;
   store::Item_t lenItem;
-  xs_long startPos;
-  xs_long len;
+  xs_integer startPos;
+  xs_integer len;
 
   dynamic_context* dctx = (theIsLocal ?
                            planState.theLocalDynCtx :
@@ -417,13 +414,13 @@
       ZORBA_ASSERT(false);
     }
 
-    startPos = posItem->getLongValue();
+    startPos = posItem->getIntegerValue();
 
     dctx->get_variable(theVarId, theVarName, loc, varSingleItem, state->theTempSeq);
 
     if (varSingleItem != NULL)
     {
-      if (startPos == 1)
+      if (startPos == Integer(1))
       {
         result.transfer(varSingleItem);
         STACK_PUSH(true, state);
@@ -431,9 +428,9 @@
     }
     else if (state->theTempSeq != NULL)
     {
-      if (startPos > 0)
+      if (startPos > Integer(0))
       {
-        state->theTempSeq->getItem((ulong)startPos, result);
+        state->theTempSeq->getItem(startPos, result);
       }
 
       if (result)
@@ -441,13 +438,8 @@
     }
     else
     {
-      throw XQUERY_EXCEPTION(
-        err::XPDY0002,
-        ERROR_PARAMS(
-          theVarName->getStringValue(), ZED( VariabledUndeclared )
-        ),
-        ERROR_LOC( loc )
-      );
+      RAISE_ERROR(err::XPDY0002, loc,
+      ERROR_PARAMS(theVarName->getStringValue(), ZED(VariabledUndeclared)));
     }
   } // if (theTargetPosIter != NULL && theTargetLenIter == NULL)
 
@@ -460,29 +452,29 @@
       ZORBA_ASSERT(false);
     }
 
-    startPos = posItem->getLongValue();
+    startPos = posItem->getIntegerValue();
 
     if (!consumeNext(lenItem, theTargetLenIter, planState))
     {
       ZORBA_ASSERT(false);
     }
 
-    len = lenItem->getLongValue();
+    len = lenItem->getIntegerValue();
 
-    if (startPos <= 0)
+    if (startPos <= Integer(0))
     {
-      len += startPos - 1;
+      len += startPos - Integer(1);
       startPos = 1;
     }
 
-    state->theLastPos = (ulong)(startPos + len);
-    state->thePos = (ulong)startPos;
+    state->theLastPos = startPos + len;
+    state->thePos = startPos;
 
     dctx->get_variable(theVarId, theVarName, loc, varSingleItem, state->theTempSeq);
 
     if (varSingleItem != NULL)
     {
-      if (state->thePos == 1 && state->thePos < state->theLastPos)
+      if (state->thePos == Integer(1) && state->thePos < state->theLastPos)
       {
         result.transfer(varSingleItem);
         STACK_PUSH(true, state);
@@ -498,21 +490,16 @@
           STACK_PUSH(true, state);
         else
           break;
-        }
+      }
     }
     else
     {
-      throw XQUERY_EXCEPTION(
-        err::XPDY0002,
-        ERROR_PARAMS(
-          theVarName->getStringValue(), ZED( VariabledUndeclared )
-        ),
-        ERROR_LOC( loc )
-      );
+      RAISE_ERROR(err::XPDY0002, loc,
+      ERROR_PARAMS(theVarName->getStringValue(), ZED(VariabledUndeclared)));
     }
   } // if (theTargetPosIter != NULL && theTargetLenIter != NULL)
 
-  else if (theTargetPos > 0)
+  else if (theTargetPos > Integer(0))
   {
     result = NULL;
 
@@ -522,7 +509,7 @@
 
     if (varSingleItem != NULL)
     {
-      if (startPos == 1)
+      if (startPos == Integer(1))
       {
         result.transfer(varSingleItem);
         STACK_PUSH(true, state);
@@ -530,9 +517,9 @@
     }
     else if (state->theTempSeq != NULL)
     {
-      if (startPos > 0)
+      if (startPos > Integer(0))
       {
-        state->theTempSeq->getItem((ulong)startPos, result);
+        state->theTempSeq->getItem(startPos, result);
       }
 
       if (result)
@@ -540,13 +527,8 @@
     }
     else
     {
-      throw XQUERY_EXCEPTION(
-        err::XPDY0002,
-        ERROR_PARAMS(
-          theVarName->getStringValue(), ZED( VariabledUndeclared )
-        ),
-        ERROR_LOC( loc )
-      );
+      RAISE_ERROR(err::XPDY0002, loc,
+      ERROR_PARAMS(theVarName->getStringValue(), ZED(VariabledUndeclared)));
     }
   } // if (theTargetPos > 0)
 
@@ -573,17 +555,12 @@
     }
     else
     {
-      throw XQUERY_EXCEPTION(
-        err::XPDY0002,
-        ERROR_PARAMS(
-          theVarName->getStringValue(), ZED( VariabledUndeclared )
-        ),
-        ERROR_LOC( loc )
-      );
+      RAISE_ERROR(err::XPDY0002, loc,
+      ERROR_PARAMS(theVarName->getStringValue(), ZED(VariabledUndeclared)));
     }
 	}
 
-  STACK_END (state);
+  STACK_END(state);
 }
 
 
@@ -696,9 +673,9 @@
 }
 
 
-bool LetVarIterator::setTargetPos(xs_long v)
+bool LetVarIterator::setTargetPos(xs_integer v)
 {
-  if (theTargetPos == 0 && theTargetPosIter == NULL)
+  if (theTargetPos == Integer(0) && theTargetPosIter == NULL)
   {
     theTargetPos = v;
     return true;
@@ -709,7 +686,7 @@
 
 bool LetVarIterator::setTargetPosIter(const PlanIter_t& v)
 {
-  if (theTargetPos == 0 && theTargetPosIter == NULL)
+  if (theTargetPos == Integer(0) && theTargetPosIter == NULL)
   {
     theTargetPosIter = v;
     return true;
@@ -720,7 +697,7 @@
 
 bool LetVarIterator::setTargetLenIter(const PlanIter_t& v)
 {
-  if (theTargetPos == 0 && theTargetLenIter == NULL)
+  if (theTargetPos == Integer(0) && theTargetLenIter == NULL)
   {
     theTargetLenIter = v;
     return true;
@@ -753,9 +730,9 @@
 
   if (theTargetPosIter == NULL)
   {
-    if (theTargetPos > 0)
+    if (theTargetPos > Integer(0))
     {
-      value->getItem((ulong)theTargetPos, state->theItem);
+      value->getItem(theTargetPos, state->theItem);
     }
     else
     {
@@ -782,9 +759,9 @@
 
   if (theTargetPosIter == NULL)
   {
-    if (theTargetPos > 0)
+    if (theTargetPos > Integer(0))
     {
-      value->getItem((ulong)(startPos + theTargetPos - 1), state->theItem);
+      value->getItem((Integer(startPos) + theTargetPos - Integer(1)), state->theItem);
     }
     else
     {
@@ -855,8 +832,8 @@
 {
   store::Item_t posItem;
   store::Item_t lenItem;
-  xs_long startPos;
-  xs_long len;
+  xs_integer startPos;
+  xs_integer len;
 
   LetVarState* state;
   DEFAULT_STACK_INIT(LetVarState, state, planState);
@@ -870,12 +847,12 @@
       ZORBA_ASSERT(false);
     }
 
-    startPos = posItem->getLongValue();
+    startPos = posItem->getIntegerValue();
 
     if (theTargetLenIter == NULL)
     {
-      if (startPos > 0)
-        state->theTempSeq->getItem((ulong)startPos, result);
+      if (startPos > Integer(0))
+        state->theTempSeq->getItem(startPos, result);
 
       if (result)
         STACK_PUSH(true, state);
@@ -887,16 +864,16 @@
         ZORBA_ASSERT(false);
       }
 
-      len = lenItem->getLongValue();
+      len = lenItem->getIntegerValue();
 
-      if (startPos <= 0)
+      if (startPos <= Integer(0))
       {
-        len += startPos - 1;
+        len += startPos - Integer(1);
         startPos = 1;
       }
 
-      state->theLastPos = (ulong)(startPos + len);
-      state->thePos = (ulong)startPos;
+      state->theLastPos = startPos + len;
+      state->thePos = startPos;
 
       while (state->thePos < state->theLastPos)
       {
@@ -909,7 +886,7 @@
       }
     }
   }
-  else if (theTargetPos > 0)
+  else if (theTargetPos > Integer(0))
   {
     result = state->theItem;
     if (result)

=== modified file 'src/runtime/core/var_iterators.h'
--- src/runtime/core/var_iterators.h	2011-06-14 17:26:33 +0000
+++ src/runtime/core/var_iterators.h	2011-12-14 03:25:21 +0000
@@ -228,8 +228,8 @@
   store::Iterator_t theSourceIter;
   store::Item_t     theItem;
 
-  ulong             thePos;
-  ulong             theLastPos;
+  xs_integer        thePos;
+  xs_integer        theLastPos;
 
 public:
   CtxVarState();
@@ -247,7 +247,7 @@
   store::Item_t  theVarName;
   bool           theIsLocal;
 
-  xs_long        theTargetPos;
+  xs_integer     theTargetPos;
   PlanIter_t     theTargetPosIter;
   PlanIter_t     theTargetLenIter;
 
@@ -276,13 +276,13 @@
 
   bool isLocal() const { return theIsLocal; }
 
-  bool setTargetPos(xs_long v);
+  bool setTargetPos(xs_integer v);
 
   bool setTargetPosIter(const PlanIter_t& v);
 
   bool setTargetLenIter(const PlanIter_t& v);
 
-  xs_long getTargetPos() const { return theTargetPos; }
+  xs_integer getTargetPos() const { return theTargetPos; }
 
   PlanIterator* getTargetPosIter() const { return theTargetPosIter.getp(); }
 
@@ -380,8 +380,8 @@
   store::Iterator_t theSourceIter;
   store::Item_t     theItem;
 
-  ulong             thePos;
-  ulong             theLastPos;
+  xs_integer        thePos;
+  xs_integer        theLastPos;
 
 public:
   LetVarState();
@@ -396,7 +396,7 @@
 {
 private:
   store::Item_t  theVarName;
-  xs_long        theTargetPos;
+  xs_integer     theTargetPos;
   PlanIter_t     theTargetPosIter;
   PlanIter_t     theTargetLenIter;
 
@@ -411,19 +411,19 @@
 
 public:
   LetVarIterator(
-        static_context* sctx,
-        const QueryLoc& loc, 
-        store::Item* name);
+      static_context* sctx,
+      const QueryLoc& loc, 
+      store::Item* name);
 
   ~LetVarIterator() {}
 
-  bool setTargetPos(xs_long v);
+  bool setTargetPos(xs_integer v);
 
   bool setTargetPosIter(const PlanIter_t& v);
 
   bool setTargetLenIter(const PlanIter_t& v);
 
-  xs_long getTargetPos() const { return theTargetPos; }
+  xs_integer getTargetPos() const { return theTargetPos; }
 
   PlanIterator* getTargetPosIter() const { return theTargetPosIter.getp(); }
 

=== modified file 'src/runtime/misc/materialize.cpp'
--- src/runtime/misc/materialize.cpp	2011-06-14 17:26:33 +0000
+++ src/runtime/misc/materialize.cpp	2011-12-14 03:25:21 +0000
@@ -76,7 +76,7 @@
   MaterializeIteratorState* state;
   DEFAULT_STACK_INIT(MaterializeIteratorState, state, planState);
 
-  state->theTempSeq->init(state->theChildWrapper, false);
+  state->theTempSeq->init(state->theChildWrapper);
 
   state->theTempSeqIter = state->theTempSeq->getIterator();
 

=== modified file 'src/runtime/visitors/printer_visitor_impl.cpp'
--- src/runtime/visitors/printer_visitor_impl.cpp	2011-12-07 22:52:43 +0000
+++ src/runtime/visitors/printer_visitor_impl.cpp	2011-12-14 03:25:21 +0000
@@ -681,8 +681,8 @@
 
   thePrinter.addAttribute("varname", a.getVarName()->getStringValue().c_str());
 
-  if (a.getTargetPos() > 0)
-    thePrinter.addAttribute("targetPos", a.getTargetPos());
+  if (a.getTargetPos() > Integer(0))
+    thePrinter.addAttribute("targetPos", a.getTargetPos().toString().c_str());
 
   printCommons( &a, theId );
   thePrinter.endBeginVisit(theId);

=== modified file 'src/store/api/shared_types.h'
--- src/store/api/shared_types.h	2011-09-22 21:50:20 +0000
+++ src/store/api/shared_types.h	2011-12-14 03:25:21 +0000
@@ -62,6 +62,9 @@
 class TempSeq;
 typedef rchandle<TempSeq> TempSeq_t;
 
+class TempSeqIterator;
+typedef rchandle<TempSeqIterator> TempSeqIterator_t;
+
 class Collection;
 typedef rchandle<Collection> Collection_t;
 

=== modified file 'src/store/api/store.h'
--- src/store/api/store.h	2011-10-12 10:12:26 +0000
+++ src/store/api/store.h	2011-12-14 03:25:21 +0000
@@ -72,15 +72,17 @@
    *                   evaluated lazily. For XQueryP it might be necassary to set
    *                   this to false.
    */
-  virtual TempSeq_t createTempSeq(
-        Iterator_t& iterator,
-        bool copyNodes,
-        bool lazy) = 0;
-
-  /**
-   * Creates a new TempSeq that is initialized with the given vector.
-   */
-  virtual TempSeq_t createTempSeq(const std::vector<Item_t>& item_v) = 0;
+  virtual TempSeq_t createTempSeq(const Iterator_t& iterator, bool lazy) = 0;
+
+  /**
+   * Creates a new TempSeq that is initialized with the given vector.
+   */
+  virtual TempSeq_t createTempSeq(std::vector<Item_t>& item_v) = 0;
+
+  /**
+   * Creates a new TempSeq that is initialized with the given vector.
+   */
+  virtual TempSeq_t createTempSeq(Item_t& item) = 0;
 
   /**
    * Creates a new, empty TempSeq.

=== modified file 'src/store/api/temp_seq.h'
--- src/store/api/temp_seq.h	2011-06-28 23:34:08 +0000
+++ src/store/api/temp_seq.h	2011-12-14 03:25:21 +0000
@@ -39,56 +39,13 @@
   /**
    * Initializes a temp sequence with the given input iterator
    */
-  virtual void init(store::Iterator_t& iter, bool copy = false) = 0;
+  virtual void init(const store::Iterator_t& iter) = 0;
 
   /**
    * Appends the items from the iterator to the temp sequence
    */
-  virtual void append(Iterator_t iter, bool copy) = 0;
-	
-  /**
-   * Reads the whole Sequence from beginning to end; it is allowed to have several 
-   * concurrent iterators on the same TempSeq.
-   * 
-   * @return Iterator which iterates over the complete TempSeq
-   * 
-   */
-  virtual Iterator_t getIterator() = 0;
-	
-  /**
-   * Returns an iterator which reads just a part of the underlying TempSeq
-   * Starts counting with 1.
-   *
-   * @param startPos The first item which the iterator returns. Starts counting with 1.
-   * @param endPos The last item which the iterator returns 
-   * @return Iterator
-   */
-  virtual Iterator_t getIterator(
-        xs_integer startPos,
-        xs_integer endPos,
-        bool streaming = false) = 0;
-		
-  /**
-   * Gets an item at a certain position.
-   * 
-   * Starts counting with 1.
-   *
-   * @param position (first position in XQuery is 1 and not 0!)
-   * @return item
-   */
-  virtual void getItem(xs_integer position, Item_t& result) = 0;
-		
-		
-  /**
-   * Returns true if the item at the passed position is available.
-   * 
-   * Starts counting with 1.
-   *
-   * @param position 
-   * @return 
-   */
-  virtual bool containsItem(xs_integer position) = 0;
-		
+  virtual void append(const Iterator_t& iter) = 0;
+	
   /**
    * purge() allows the store to do proper garbage collection. If e.g. a let 
    * has created iterators for all his bindings he has to produce, it can
@@ -107,11 +64,54 @@
    * @param upTo boundary for garbage collector
    */
   virtual void purgeUpTo(xs_integer upTo) = 0;
-		
+
   /**
    * @return Does this TempSeq save an empty sequence? 
    */
   virtual bool empty() = 0;
+
+  /**
+   * Gets an item at a certain position.
+   * 
+   * Starts counting with 1.
+   *
+   * @param position (first position in XQuery is 1 and not 0!)
+   * @return item
+   */
+  virtual void getItem(xs_integer position, Item_t& result) = 0;
+		
+		
+  /**
+   * Returns true if the item at the passed position is available.
+   * 
+   * Starts counting with 1.
+   *
+   * @param position 
+   * @return 
+   */
+  virtual bool containsItem(xs_integer position) = 0;
+
+  /**
+   * Reads the whole Sequence from beginning to end; it is allowed to have several 
+   * concurrent iterators on the same TempSeq.
+   * 
+   * @return Iterator which iterates over the complete TempSeq
+   * 
+   */
+  virtual Iterator_t getIterator() const = 0;
+	
+  /**
+   * Returns an iterator which reads just a part of the underlying TempSeq
+   * Starts counting with 1.
+   *
+   * @param startPos The first item which the iterator returns. Starts counting with 1.
+   * @param endPos The last item which the iterator returns 
+   * @return Iterator
+   */
+  virtual Iterator_t getIterator(
+      xs_integer startPos,
+      xs_integer endPos,
+      bool streaming = false) const = 0;
 };
 
 } // namespace store

=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp	2011-10-27 20:55:51 +0000
+++ src/store/naive/atomic_items.cpp	2011-12-14 03:25:21 +0000
@@ -2441,10 +2441,8 @@
   }
   catch ( std::range_error const& )
   {
-    throw XQUERY_EXCEPTION(
-      err::FORG0001,
-      ERROR_PARAMS( theValue, ZED( CastFromToFailed_34 ), "integer", "long" )
-    );
+    RAISE_ERROR_NO_LOC(err::FORG0001,
+    ERROR_PARAMS(theValue, ZED(CastFromToFailed_34), "integer", "long"));
   }
 }
 

=== modified file 'src/store/naive/simple_lazy_temp_seq.cpp'
--- src/store/naive/simple_lazy_temp_seq.cpp	2011-07-13 17:53:51 +0000
+++ src/store/naive/simple_lazy_temp_seq.cpp	2011-12-14 03:25:21 +0000
@@ -16,7 +16,9 @@
 #include "stdafx.h"
 #include <limits>
 
+#include "diagnostics/xquery_exception.h"
 #include "diagnostics/assert.h"
+#include "diagnostics/util_macros.h"
 
 #include "store/api/item.h"
 #include "store/naive/simple_lazy_temp_seq.h"
@@ -31,9 +33,9 @@
 /*******************************************************************************
 
 ********************************************************************************/
-SimpleLazyTempSeq::SimpleLazyTempSeq(store::Iterator_t& aIter, bool aCopy)
+SimpleLazyTempSeq::SimpleLazyTempSeq(const store::Iterator_t& aIter)
 {
-  init(aIter, aCopy);
+  init(aIter);
 }
 
 
@@ -48,34 +50,9 @@
 /*******************************************************************************
 
 ********************************************************************************/
-bool SimpleLazyTempSeq::empty()
-{
-  if ( theItems.size() > 0 )
-  {
-    return false;
-  }
-  else
-  {
-    if ( theMatFinished )
-    {
-      return true;
-    }
-    else
-    {
-      matNextItem();
-      return theItems.empty();
-    }
-  }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void SimpleLazyTempSeq::init(store::Iterator_t& aIter, bool aCopy)
+void SimpleLazyTempSeq::init(const store::Iterator_t& aIter)
 {
   theIterator = aIter;
-  theCopy = aCopy;
   theMatFinished = false;
   thePurgedUpTo = 0;
   theItems.clear();
@@ -85,15 +62,15 @@
 /*******************************************************************************
 
 ********************************************************************************/
-void SimpleLazyTempSeq::append(store::Iterator_t iter, bool copy)
+void SimpleLazyTempSeq::append(const store::Iterator_t& iter)
 {
   while (!theMatFinished)
   {
     matNextItem();
   }
+
   theMatFinished = false;
   theIterator = iter;
-  theCopy = copy;
 }
 
 
@@ -111,18 +88,17 @@
 ********************************************************************************/
 void SimpleLazyTempSeq::purgeUpTo(xs_integer upTo)
 {
-  ulong lUpTo;
-  try {
-    lUpTo = to_xs_unsignedLong(upTo);
-  } catch (std::range_error& e)
-  {
-    throw ZORBA_EXCEPTION(
-        zerr::ZSTR0060_RANGE_EXCEPTION,
-        ERROR_PARAMS(
-          BUILD_STRING("sequence too big (" << e.what() << ")")
-        )
-      );
-  }
+  xs_long lUpTo;
+  try 
+  {
+    lUpTo = to_xs_long(upTo);
+  }
+  catch (std::range_error& e)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZSTR0060_RANGE_EXCEPTION,
+    ERROR_PARAMS(BUILD_STRING("sequence too big (" << e.what() << ")")));
+  }
+
   ZORBA_ASSERT(lUpTo >= thePurgedUpTo);
   ZORBA_ASSERT(lUpTo - thePurgedUpTo <= theItems.size());
 
@@ -132,12 +108,137 @@
 
 
 /*******************************************************************************
+
+********************************************************************************/
+bool SimpleLazyTempSeq::empty()
+{
+  if (!theItems.empty())
+  {
+    return false;
+  }
+  else
+  {
+    if (theMatFinished)
+    {
+      return true;
+    }
+    else
+    {
+      matNextItem();
+      return theItems.empty();
+    }
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void SimpleLazyTempSeq::getItem(xs_integer position, store::Item_t& result)
+{
+  xs_long lPos;
+  try 
+  {
+    lPos = to_xs_long(position);
+  }
+  catch (std::range_error& e)
+  {
+    RAISE_ERROR_NO_LOC(zerr::ZSTR0060_RANGE_EXCEPTION,
+    ERROR_PARAMS(BUILD_STRING("access out of bounds " << e.what() << ")")));
+  }
+
+  if (this->containsItem(position)) 
+  {
+    result = theItems[lPos - thePurgedUpTo - 1];
+  }
+  else 
+  {
+    result = NULL;
+  }
+}
+
+
+/*******************************************************************************
+  This method checks if the i-th item in the result sequences of the input
+  iterator is in the queue or not. In general, the item may be missing from
+  the queue because:
+  (a) it has either been purged, or
+  (b) it has not been computed yet, or
+  (c) the result sequence contains less than i items.
+ 
+  Case (a) should never arise: it is the user of the lazy temp sequence that
+  decided when and how many items to purge, so he shouldn't come back to ask
+  for an item that has been purged.
+
+  In case (c), the method will compute and buffer any input items that have not
+  been computed already and then return false.
+
+  In case (b), the method will compute and buffer all the items starting after
+  the last computed item and up to the i-th item; then it will return true.
+
+  If the i-th item is already in the queue, the method will simply return true. 
+********************************************************************************/
+inline bool SimpleLazyTempSeq::containsItem(xs_integer position) 
+{
+  xs_long lPos;
+  try 
+  {
+    lPos = to_xs_long(position);
+  }
+  catch (std::range_error& e)
+  {
+    RAISE_ERROR_NO_LOC(zerr::ZSTR0060_RANGE_EXCEPTION,
+    ERROR_PARAMS(BUILD_STRING("access out of bounds " << e.what() << ")")));
+  }
+
+  assert(lPos > thePurgedUpTo);
+
+  xs_long numItemsToBuffer = lPos - thePurgedUpTo;
+
+  while (!theMatFinished && theItems.size() <  numItemsToBuffer) 
+  {
+    matNextItem();
+  }
+
+  return theItems.size() >= numItemsToBuffer;
+}
+
+
+/*******************************************************************************
+  Get the next item (if any) from the input iterator and put it at the end of 
+  the queue.  
+********************************************************************************/
+void SimpleLazyTempSeq::matNextItem() 
+{
+  theItems.push_back(NULL);
+
+  store::Item_t& lLocation = theItems.back();
+
+  if (theIterator->next(lLocation)) 
+  {
+    if (theCopy && lLocation->isNode()) 
+    {
+      store::CopyMode lCopyMode;
+      lLocation = lLocation->copy(NULL, lCopyMode);
+    }
+  }
+  else 
+  {
+    // We do not want to have an empty item materialized.
+    theItems.pop_back();
+    theMatFinished = true;
+    theIterator->close();
+  }
+}
+
+
+/*******************************************************************************
   Reads the whole Sequence from beginning to end; it is allowed to have several
   concurrent iterators on the same TempSeq.
 
   @return Iterator which iterates over the complete TempSeq
 ********************************************************************************/
-store::Iterator_t SimpleLazyTempSeq::getIterator()
+store::Iterator_t SimpleLazyTempSeq::getIterator() const
 {
   return new SimpleLazyTempSeqIter(this, 1, std::numeric_limits<long>::max());
 }
@@ -153,7 +254,7 @@
 store::Iterator_t SimpleLazyTempSeq::getIterator(
     xs_integer startPos,
     xs_integer endPos,
-    bool streaming)
+    bool streaming) const
 {
   return new SimpleLazyTempSeqIter(this, startPos, endPos);
 }
@@ -162,62 +263,23 @@
 /*******************************************************************************
 
 ********************************************************************************/
-store::Iterator_t SimpleLazyTempSeq::getIterator(
-    xs_integer startPos,
-    store::Iterator_t function,
-    const std::vector<store::Iterator_t>& vars,
-    bool streaming)
-{
-  assert(false); //Not implemented
-  return store::Iterator_t(NULL);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-store::Iterator_t SimpleLazyTempSeq::getIterator(
-    const std::vector<xs_integer>& positions,
-    bool streaming)
-{
-  assert (false); //Not implemented
-  return store::Iterator_t(NULL);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-store::Iterator_t SimpleLazyTempSeq::getIterator(
-    store::Iterator_t positions,
-    bool streaming)
-{
-  assert(false); //Not implemented
-  return store::Iterator_t ( NULL );
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
 SimpleLazyTempSeqIter::SimpleLazyTempSeqIter(
-    SimpleLazyTempSeq_t aTempSeq,
+    const SimpleLazyTempSeq* aTempSeq,
     xs_integer aStartPos,
     xs_integer aEndPos)
-  : theTempSeq(aTempSeq)
+  :
+  theTempSeq(const_cast<SimpleLazyTempSeq*>(aTempSeq))
 {
-  try {
-    theCurPos = to_xs_unsignedLong(aStartPos) - 1;
-    theStartPos = to_xs_unsignedLong(aStartPos);
-    theEndPos = to_xs_unsignedLong(aEndPos);
-  } catch (std::range_error& e)
-  {
-    throw ZORBA_EXCEPTION(
-        zerr::ZSTR0060_RANGE_EXCEPTION,
-        ERROR_PARAMS(
-          BUILD_STRING("sequence too big (" << e.what() << ")")
-        )
-      );
+  try 
+  {
+    theCurPos = to_xs_long(aStartPos) - 1;
+    theStartPos = to_xs_long(aStartPos);
+    theEndPos = to_xs_long(aEndPos);
+  }
+  catch (std::range_error& e)
+  {
+    RAISE_ERROR_NO_LOC(zerr::ZSTR0060_RANGE_EXCEPTION,
+    ERROR_PARAMS(BUILD_STRING("sequence too big (" << e.what() << ")")));
   }
 }
 

=== modified file 'src/store/naive/simple_lazy_temp_seq.h'
--- src/store/naive/simple_lazy_temp_seq.h	2011-07-29 23:01:30 +0000
+++ src/store/naive/simple_lazy_temp_seq.h	2011-12-14 03:25:21 +0000
@@ -51,71 +51,60 @@
   store::Iterator_t          theIterator;
   bool                       theCopy;
   bool                       theMatFinished;
-  uint64_t                      thePurgedUpTo;
+  xs_long                    thePurgedUpTo;
   
   std::vector<store::Item_t> theItems;
 
  public:
   SimpleLazyTempSeq() { }
 
-  SimpleLazyTempSeq(store::Iterator_t& iter, bool copy = false);
+  SimpleLazyTempSeq(const store::Iterator_t& iter);
 
   virtual ~SimpleLazyTempSeq();
 
-  bool empty();
-
-  void init(store::Iterator_t& iter, bool copy = false);
-
-  void append(store::Iterator_t iter, bool copy);
-
-  inline void getItem(xs_integer position, store::Item_t& result);
-
-  inline bool containsItem(xs_integer position);
-
-  store::Iterator_t getIterator();
-
-  store::Iterator_t getIterator(
-        xs_integer startPos,
-        xs_integer endPos,
-        bool streaming = false);
-
-  store::Iterator_t getIterator(
-        xs_integer startPos,
-        store::Iterator_t function,
-        const std::vector<store::Iterator_t>& var,
-        bool streaming = false);
-
-  store::Iterator_t getIterator(
-        const std::vector<xs_integer>& positions,
-        bool streaming = false);
-
-  store::Iterator_t getIterator(
-        store::Iterator_t positions,
-        bool streaming = false);
-        
+  void init(const store::Iterator_t& iter);
+
+  void append(const store::Iterator_t& iter);
+
   void purge();
 
   void purgeUpTo(xs_integer upTo);
 
+  bool empty();
+
+  void getItem(xs_integer position, store::Item_t& result);
+
+  bool containsItem(xs_integer position);
+
+  store::Iterator_t getIterator() const;
+
+  store::Iterator_t getIterator(
+      xs_integer startPos,
+      xs_integer endPos,
+      bool streaming = false) const;
+
  private:
-  inline void matNextItem();
+  void matNextItem();
 };
  
  
+/*******************************************************************************
+
+********************************************************************************/
 class SimpleLazyTempSeqIter : public store::Iterator 
 {
  private:
   SimpleLazyTempSeq_t  theTempSeq;
 
-  uint64_t             theCurPos;
-  uint64_t             theStartPos;
-  uint64_t             theEndPos;
+  xs_long              theCurPos;
+  xs_long              theStartPos;
+  xs_long              theEndPos;
 
  public:
   SimpleLazyTempSeqIter(
-        SimpleLazyTempSeq_t aTempSeq,
-        xs_integer aStartPos,
-        xs_integer aEndPos);
+      const SimpleLazyTempSeq* aTempSeq,
+      xs_integer aStartPos,
+      xs_integer aEndPos);
 
   virtual ~SimpleLazyTempSeqIter();
 
@@ -126,110 +115,6 @@
 };
 
 
-
-/*******************************************************************************
-
-********************************************************************************/
-inline void SimpleLazyTempSeq::getItem(xs_integer position, store::Item_t& result)
-{
-  uint64_t lPos;
-  try {
-    lPos = to_xs_unsignedLong(position);
-  } catch (std::range_error& e)
-  {
-    throw ZORBA_EXCEPTION(
-        zerr::ZSTR0060_RANGE_EXCEPTION,
-        ERROR_PARAMS(
-          BUILD_STRING("access out of bounds " << e.what() << ")")
-        )
-      );
-  }
-  if ( this->containsItem ( lPos ) ) 
-  {
-    result = theItems[lPos - thePurgedUpTo - 1];
-  }
-  else 
-  {
-    result = NULL;
-  }
-}
-
-
-/*******************************************************************************
-  This method checks if the i-th item in the result sequences of the input
-  iterator is in the queue or not. In general, the item may be missing from
-  the queue because:
-  (a) it has either been purged, or
-  (b) it has not been computed yet, or
-  (c) the result sequence contains less than i items.
- 
-  Case (a) should never arise: it is the user of the lazy temp sequence that
-  decided when and how many items to purge, so he shouldn't come back to ask
-  for an item that has been purged.
-
-  In case (c), the method will compute and buffer any input items that have not
-  been computed already and then return false.
-
-  In case (b), the method will compute and buffer all the items starting after
-  the last computed item and up to the i-th item; then it will return true.
-
-  If the i-th item is already in the queue, the method will simply return true. 
-********************************************************************************/
-inline bool SimpleLazyTempSeq::containsItem(xs_integer position) 
-{
-  uint64_t lPos;
-  try {
-    lPos = to_xs_unsignedLong(position);
-  } catch (std::range_error& e)
-  {
-    throw ZORBA_EXCEPTION(
-        zerr::ZSTR0060_RANGE_EXCEPTION,
-        ERROR_PARAMS(
-          BUILD_STRING("access out of bounds " << e.what() << ")")
-        )
-      );
-  }
-  assert(lPos > thePurgedUpTo);
-
-  uint64_t numItemsToBuffer = lPos - thePurgedUpTo;
-
-  while (!theMatFinished && theItems.size() <  numItemsToBuffer) 
-  {
-    matNextItem();
-  }
-
-  return theItems.size() >= numItemsToBuffer;
-}
-
-
-/*******************************************************************************
-  Get the next item (if any) from the input iterator and put it at the end of 
-  the queue.  
-********************************************************************************/
-inline void SimpleLazyTempSeq::matNextItem() 
-{
-  theItems.push_back(NULL);
-
-  store::Item_t& lLocation = theItems.back();
-
-  if (theIterator->next(lLocation)) 
-  {
-    if (theCopy && lLocation->isNode()) 
-    {
-      store::CopyMode lCopyMode;
-      lLocation = lLocation->copy(NULL, lCopyMode);
-    }
-  }
-  else 
-  {
-    // We do not want to have an empty item materialized.
-    theItems.pop_back();
-    theMatFinished = true;
-    theIterator->close();
-  }
-}
-
-
 } // namespace store
 } // namespace zorba
 

=== modified file 'src/store/naive/simple_store.cpp'
--- src/store/naive/simple_store.cpp	2011-11-17 03:04:59 +0000
+++ src/store/naive/simple_store.cpp	2011-12-14 03:25:21 +0000
@@ -1484,25 +1484,20 @@
   Creates a new TempSeq. The instance can be used, e.g. for variable bindings
 
   @param iterator   The source for the XMDInstance
-  @param copyNodes  If true, all nodes are copied before they are saved in the
-                    temp sequence.
   @param lazy       Hint for the store. If possible a XMDInstance should be
                     evaluated lazily. For XQueryP it might be necassary to set
                     this to false.
 ********************************************************************************/
-TempSeq_t SimpleStore::createTempSeq(
-    store::Iterator_t& iterator,
-    bool copyNodes,
-    bool lazy)
+TempSeq_t SimpleStore::createTempSeq(const store::Iterator_t& iterator, bool lazy)
 {
   if(lazy)
   {
     //tempSeq = new SimpleTempSeq(iterator, copyNodes);
-    return new SimpleLazyTempSeq(iterator, copyNodes);
+    return new SimpleLazyTempSeq(iterator);
   }
   else
   {
-    return new SimpleTempSeq(iterator, copyNodes);
+    return new SimpleTempSeq(iterator);
   }
 }
 
@@ -1512,7 +1507,6 @@
 ********************************************************************************/
 TempSeq_t SimpleStore::createTempSeq(bool lazy)
 {
-  TempSeq_t tempSeq;
   if (lazy)
   {
     return new SimpleLazyTempSeq();
@@ -1528,27 +1522,43 @@
   Creates a temp seq initialized by the given vector.
   @param item_v - The vector to use to initialize the seq.
 ********************************************************************************/
-TempSeq_t SimpleStore::createTempSeq(const std::vector<store::Item_t>& item_v)
-{
-  TempSeq_t tempSeq = new SimpleTempSeq(item_v);
-  return tempSeq;
-}
+TempSeq_t SimpleStore::createTempSeq(std::vector<store::Item_t>& items)
+{
+  return new SimpleTempSeq(items);
+}
+
+
+/*******************************************************************************
+  Creates a temp seq initialized by the given item.
+********************************************************************************/
+TempSeq_t SimpleStore::createTempSeq(store::Item_t& item)
+{
+  return new SimpleTempSeq(item);
+}
+
 
 #ifndef ZORBA_NO_FULL_TEXT
-void SimpleStore::setStemmerProvider( internal::StemmerProvider const *p ) {
+void SimpleStore::setStemmerProvider( internal::StemmerProvider const *p ) 
+{
   theStemmerProvider = p;
 }
 
-void SimpleStore::setTokenizerProvider( TokenizerProvider const *p ) {
+
+void SimpleStore::setTokenizerProvider( TokenizerProvider const *p ) 
+{
   theTokenizerProvider = p;
 }
 
-internal::StemmerProvider const* SimpleStore::getStemmerProvider() const {
+
+internal::StemmerProvider const* SimpleStore::getStemmerProvider() const 
+{
   return theStemmerProvider ?
     theStemmerProvider : &internal::StemmerProvider::get_default();
 }
 
-TokenizerProvider const* SimpleStore::getTokenizerProvider() const {
+
+TokenizerProvider const* SimpleStore::getTokenizerProvider() const 
+{
   return theTokenizerProvider ?
     theTokenizerProvider : &default_tokenizer_provider();
 }

=== modified file 'src/store/naive/simple_store.h'
--- src/store/naive/simple_store.h	2011-12-01 11:02:25 +0000
+++ src/store/naive/simple_store.h	2011-12-14 03:25:21 +0000
@@ -343,12 +343,11 @@
 
   store::TempSeq_t createTempSeq(bool lazy);
 
-  store::TempSeq_t createTempSeq(
-        store::Iterator_t& iterator,
-        bool copyNodes ,
-        bool lazy);
-
-  store::TempSeq_t createTempSeq(const std::vector<store::Item_t>& item_v);
+  store::TempSeq_t createTempSeq(const store::Iterator_t& iterator, bool lazy);
+
+  store::TempSeq_t createTempSeq(std::vector<store::Item_t>& item_v);
+
+  store::TempSeq_t createTempSeq(store::Item_t& item);
 
 #ifndef ZORBA_NO_FULL_TEXT
   internal::StemmerProvider const* getStemmerProvider() const;

=== modified file 'src/store/naive/simple_temp_seq.cpp'
--- src/store/naive/simple_temp_seq.cpp	2011-12-13 02:35:39 +0000
+++ src/store/naive/simple_temp_seq.cpp	2011-12-14 03:25:21 +0000
@@ -15,21 +15,32 @@
  */
 #include "stdafx.h"
 
-#include "diagnostics/zorba_exception.h"
+#include "diagnostics/xquery_exception.h"
 #include "zorba/diagnostic_list.h"
 #include "diagnostics/diagnostic.h"
+#include "diagnostics/util_macros.h"
+
 #include "store/api/item.h"
 #include "store/naive/simple_temp_seq.h"
 #include "store/api/copymode.h"
 
 namespace zorba { namespace simplestore {
 
+
 /*******************************************************************************
 
 ********************************************************************************/
-SimpleTempSeq::SimpleTempSeq(store::Iterator_t& iter, bool copy)
+SimpleTempSeq::SimpleTempSeq(std::vector<store::Item_t>& items)
 {
-  init(iter, copy);
+  theItems.resize(items.size());
+
+  std::vector<store::Item_t>::iterator ite = items.begin();
+  std::vector<store::Item_t>::iterator end = items.end();
+  std::vector<store::Item*>::iterator ite2 = theItems.begin();
+  for (; ite != end; ++ite, ++ite2)
+  {
+    (*ite2) = (*ite).release();
+  }
 }
 
 
@@ -38,6 +49,73 @@
 ********************************************************************************/
 SimpleTempSeq::~SimpleTempSeq()
 {
+  clear();
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void SimpleTempSeq::clear()
+{
+  std::vector<store::Item*>::iterator ite = theItems.begin();
+  std::vector<store::Item*>::iterator end = theItems.end();
+  for (; ite != end; ++ite)
+  {
+    (*ite)->removeReference();
+  }
+
+  theItems.clear();
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void SimpleTempSeq::init(const store::Iterator_t& iter)
+{
+  store::Item_t curItem;
+
+  clear();
+
+  while (iter->next(curItem)) 
+  {
+    // TODO ???? Check that the size is less than max(csize, xs_integer)
+    theItems.push_back(NULL);
+    theItems.back() = curItem.release();
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void SimpleTempSeq::append(const store::Iterator_t& iter)
+{
+  store::Item_t curItem;
+
+  while (iter->next(curItem))
+  {
+    // TODO ???? Check that the size is less than max(csize, xs_integer)
+    theItems.push_back(NULL);
+    theItems.back() = curItem.release();
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void SimpleTempSeq::purge()
+{
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void SimpleTempSeq::purgeUpTo(xs_integer upTo)
+{
 }
 
 
@@ -46,6 +124,7 @@
 ********************************************************************************/
 bool SimpleTempSeq::empty()
 {
+<<<<<<< TREE
   return theItems.size() == 0;
 }
 
@@ -54,6 +133,16 @@
 
 ********************************************************************************/
 xs_integer SimpleTempSeq::getSize() 
+=======
+  return theItems.empty();
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+xs_integer SimpleTempSeq::getSize() const
+>>>>>>> MERGE-SOURCE
 {
   return theItems.size();
 }
@@ -64,21 +153,20 @@
 ********************************************************************************/
 void SimpleTempSeq::getItem(xs_integer position, store::Item_t& res)
 {
-  uint64_t lPos;
-  try {
-    lPos = to_xs_unsignedLong(position);
-  } catch (std::range_error& e)
-  {
-    throw ZORBA_EXCEPTION(
-        zerr::ZSTR0060_RANGE_EXCEPTION,
-        ERROR_PARAMS(
-          BUILD_STRING("access out of bounds " << e.what() << ")")
-        )
-      );
-  }
-  if (containsItem(lPos))
+  xs_long pos;
+  try 
+  {
+    pos = to_xs_long(position);
+  }
+  catch (std::range_error& e)
+  {
+    RAISE_ERROR_NO_LOC(zerr::ZSTR0060_RANGE_EXCEPTION,
+    ERROR_PARAMS(BUILD_STRING("access out of bounds " << e.what() << ")")));
+  }
+
+  if (0 < pos && pos <= theItems.size())
 	{
-    res = theItems[lPos - 1];
+    res = theItems[pos - 1];
   }
   else
 	{
@@ -92,59 +180,18 @@
 ********************************************************************************/
 bool SimpleTempSeq::containsItem(xs_integer position)
 {
-  uint64_t lPos;
-  try {
-    lPos = to_xs_unsignedLong(position);
-  } catch (std::range_error& e)
-  {
-    throw ZORBA_EXCEPTION(
-        zerr::ZSTR0060_RANGE_EXCEPTION,
-        ERROR_PARAMS(
-          BUILD_STRING("access out of bounds " << e.what() << ")")
-        )
-      );
-  }
-  return theItems.size() >= lPos;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void SimpleTempSeq::init(store::Iterator_t& iter, bool copy)
-{
-  store::CopyMode lCopyMode;
-  store::Item_t curItem;
-
-  theItems.clear();
-
-  while (iter->next(curItem)) 
-  {
-    if (copy && curItem->isNode()) 
-      curItem = curItem->copy(NULL, lCopyMode);
-
-    theItems.push_back(NULL);
-    theItems.back().transfer(curItem);
-  }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void SimpleTempSeq::append(store::Iterator_t iter, bool copy)
-{
-  store::Item_t curItem;
-  store::CopyMode lCopyMode;
-
-  while (iter->next(curItem))
-  {
-    if (copy && curItem->isNode())
-      curItem = curItem->copy(NULL, lCopyMode);
-
-    theItems.push_back(NULL);
-    theItems.back().transfer(curItem);
-  }
+  xs_long pos;
+  try 
+  {
+    pos = to_xs_long(position);
+  }
+  catch (std::range_error& e)
+  {
+    RAISE_ERROR_NO_LOC(zerr::ZSTR0060_RANGE_EXCEPTION,
+    ERROR_PARAMS(BUILD_STRING("access out of bounds " << e.what() << ")")));
+  }
+
+  return 0 < pos && pos <= theItems.size();
 }
 
 
@@ -154,7 +201,7 @@
 
   @return Iterator which iterates over the complete TempSeq
 ********************************************************************************/
-store::Iterator_t SimpleTempSeq::getIterator()
+store::Iterator_t SimpleTempSeq::getIterator() const
 {
   return new SimpleTempSeqIter(this);
 }
@@ -170,7 +217,7 @@
 store::Iterator_t SimpleTempSeq::getIterator(
     xs_integer startPos,
     xs_integer endPos,
-    bool streaming)
+    bool streaming) const
 {
   return new SimpleTempSeqIter(this, startPos, endPos);
 }
@@ -178,86 +225,49 @@
 
 /*******************************************************************************
 
-********************************************************************************/
-store::Iterator_t SimpleTempSeq::getIterator(
-    xs_integer startPos,
-    store::Iterator_t function,
-    const std::vector<store::Iterator_t>& vars,
-    bool streaming)
-{
-  return store::Iterator_t ( NULL );
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-store::Iterator_t SimpleTempSeq::getIterator(
-    const std::vector<xs_integer>& positions,
-    bool streaming)
-{
-  return store::Iterator_t ( NULL );
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-store::Iterator_t SimpleTempSeq::getIterator(
-    store::Iterator_t positions,
-    bool streaming)
-{
-  return store::Iterator_t(NULL);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void SimpleTempSeq::purge()
-{
-
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void SimpleTempSeq::purgeUpTo(xs_integer upTo)
-{
-
-}
-
-
-/*******************************************************************************
-
 ********************************************************************************/	
-SimpleTempSeqIter::SimpleTempSeqIter(
-    SimpleTempSeq_t aTempSeq)
+SimpleTempSeqIter::SimpleTempSeqIter(const SimpleTempSeq* aTempSeq)
 	:
-    theTempSeq(aTempSeq),
-    theBorderType(none),
-    theCurPos(-1)
+  theTempSeq(const_cast<SimpleTempSeq*>(aTempSeq)),
+  theBorderType(none)
 {
+  theBegin = theTempSeq->theItems.begin();
+  theEnd = theTempSeq->theItems.end();
 }
 
 
 SimpleTempSeqIter::SimpleTempSeqIter(
-    SimpleTempSeq_t aTempSeq,
+    const SimpleTempSeq* aTempSeq,
     xs_integer startPos,
     xs_integer endPos)
 	:
-		theTempSeq(aTempSeq),
-    theBorderType(startEnd),
-    theCurPos(to_xs_long(startPos) - 2),
-    theStartPos(to_xs_long(startPos)),
-    theEndPos(to_xs_long(endPos))
-{
-}
-
-
-SimpleTempSeqIter::~SimpleTempSeqIter()
-{
+  theTempSeq(const_cast<SimpleTempSeq*>(aTempSeq)),
+  theBorderType(startEnd)
+{
+  xs_long start;
+  xs_long end;
+
+  try 
+  {
+    start = to_xs_long(startPos);
+    end = to_xs_long(endPos);
+  }
+  catch (std::range_error& e)
+  {
+    RAISE_ERROR_NO_LOC(zerr::ZSTR0060_RANGE_EXCEPTION,
+    ERROR_PARAMS(BUILD_STRING("access out of bounds " << e.what() << ")")));
+  }
+
+  if (start > 0 && end > 0)
+  {
+    theBegin = theTempSeq->theItems.begin() + (start - 1);
+    theEnd = theTempSeq->theItems.begin() + end;
+  }
+  else
+  {
+    theBegin = theTempSeq->theItems.end();
+    theEnd = theTempSeq->theItems.end();
+  }
 }
 
 
@@ -265,26 +275,21 @@
 {
   theTempSeq = aTempSeq;
   theBorderType = none;
-  theCurPos = -1;
+
+  theBegin = theTempSeq->theItems.begin();
+  theEnd = theTempSeq->theItems.end();
 }
 
 
 void SimpleTempSeqIter::open()
 {
-  switch (theBorderType)
-	{
-  case startEnd:
-    theCurPos = theStartPos - 2;
-    break;
-  case none:
-    theCurPos = -1;
-    break;
-  }
+  theIte = theBegin;
 }
 
 
 bool SimpleTempSeqIter::next(store::Item_t& result)
 {
+<<<<<<< TREE
   theCurPos++;
   switch (theBorderType)
 	{
@@ -303,7 +308,15 @@
       return true;
     }
     break;
+=======
+  if (theIte != theEnd)
+  {
+    result = *theIte;
+    ++theIte;
+    return true;
+>>>>>>> MERGE-SOURCE
   }
+
   result = NULL;
   return false;
 }
@@ -311,6 +324,7 @@
 
 store::Item* SimpleTempSeqIter::next()
 {
+<<<<<<< TREE
   theCurPos++;
   switch (theBorderType)
 	{
@@ -322,6 +336,13 @@
     if ( theCurPos < theEndPos ) 
       return theTempSeq->theItems[theCurPos];
     break;
+=======
+  if (theIte != theEnd)
+  {
+    store::Item* result = *theIte;
+    ++theIte;
+    return result;
+>>>>>>> MERGE-SOURCE
   }
 
   return NULL;
@@ -330,15 +351,7 @@
 
 void SimpleTempSeqIter::reset()
 {
-  switch (theBorderType)
-	{
-  case startEnd:
-    theCurPos = theStartPos - 2;
-    break;
-  case none:
-    theCurPos = -1;
-    break;
-  }
+  theIte = theBegin;
 }
 
 

=== modified file 'src/store/naive/simple_temp_seq.h'
--- src/store/naive/simple_temp_seq.h	2011-12-13 02:35:39 +0000
+++ src/store/naive/simple_temp_seq.h	2011-12-14 03:25:21 +0000
@@ -35,55 +35,70 @@
 ********************************************************************************/
 class SimpleTempSeq : public store::TempSeq
 {
+<<<<<<< TREE
   friend class SimpleTempSeqIter;
 
 private:
   std::vector<store::Item_t> theItems;
+=======
+  friend class SimpleTempSeqIter;
+
+private:
+  std::vector<store::Item*> theItems; // ref-counting is done manually
+
+private:
+  void clear();
+>>>>>>> MERGE-SOURCE
 
 public:
   SimpleTempSeq() { }
 
-  SimpleTempSeq(const std::vector<store::Item_t>& items) : theItems(items) {}
-
-  SimpleTempSeq(store::Iterator_t& iter, bool copy = false);
+  SimpleTempSeq(store::Item_t& item) 
+  {
+    theItems.push_back(NULL);
+    theItems[0] = item.release();
+  }
+
+  SimpleTempSeq(std::vector<store::Item_t>& items);
+
+  SimpleTempSeq(const store::Iterator_t& iter)
+  {
+    init(iter);
+  }
 
   virtual ~SimpleTempSeq();
 
+  void init(const store::Iterator_t& iter);
+
+  void append(const store::Iterator_t& iter);
+
+  void purge();
+
+  void purgeUpTo(xs_integer upTo);
+
   bool empty();
   
+<<<<<<< TREE
   xs_integer getSize();
 
   void init(store::Iterator_t& iter, bool copy = false);
 
   void append(store::Iterator_t iter, bool copy);
 
+=======
+  xs_integer getSize() const;
+
+>>>>>>> MERGE-SOURCE
   void getItem(xs_integer position, store::Item_t& res);
 
   bool containsItem(xs_integer position);
 
-  store::Iterator_t getIterator();
-
-  store::Iterator_t getIterator(
-        xs_integer startPos,
-        xs_integer endPos,
-        bool streaming = false);
-
-  store::Iterator_t getIterator(
-        xs_integer startPos,
-        store::Iterator_t function,
-        const std::vector<store::Iterator_t>& var,
-        bool streaming = false );
-
-  store::Iterator_t getIterator(
-        const std::vector<xs_integer>& positions,
-        bool streaming = false);
-
-  store::Iterator_t getIterator(
-        store::Iterator_t positions,
-        bool streaming = false);
-  
-  void purge();
-  void purgeUpTo(xs_integer upTo );
+  store::Iterator_t getIterator() const;
+
+  store::Iterator_t getIterator(
+      xs_integer startPos,
+      xs_integer endPos,
+      bool streaming = false) const;
 };
 
 
@@ -99,24 +114,30 @@
     startEnd
   };
 
-  SimpleTempSeq_t     theTempSeq;
-  BorderType          theBorderType;
+  SimpleTempSeq_t                      theTempSeq;
+  BorderType                           theBorderType;
 
+<<<<<<< TREE
   uint64_t            theCurPos;
   uint64_t            theStartPos;
   uint64_t            theEndPos;
+=======
+  std::vector<store::Item*>::iterator  theIte;
+  std::vector<store::Item*>::iterator  theBegin;
+  std::vector<store::Item*>::iterator  theEnd;
+>>>>>>> MERGE-SOURCE
 
  public:
   SimpleTempSeqIter() {}
 
-  SimpleTempSeqIter(SimpleTempSeq_t aTempSeq);
+  SimpleTempSeqIter(const SimpleTempSeq* aTempSeq);
 
   SimpleTempSeqIter(
-      SimpleTempSeq_t aTempSeq,
+      const SimpleTempSeq* aTempSeq,
       xs_integer startPos,
       xs_integer endPos);
 
-  virtual ~SimpleTempSeqIter();
+  ~SimpleTempSeqIter() {}
 
   void init(const store::TempSeq_t& seq);
 

=== modified file 'test/rbkt/Queries/zorba/xmark/q12.xq'
--- test/rbkt/Queries/zorba/xmark/q12.xq	2011-06-24 19:58:33 +0000
+++ test/rbkt/Queries/zorba/xmark/q12.xq	2011-12-14 03:25:21 +0000
@@ -1,10 +1,12 @@
 declare variable $input-context external;
-let $auction := doc($input-context) return
+
+let $auction := doc($input-context) 
+return
 for $p in $auction/site/people/person
 let $l :=
-for $i in $auction/site/open_auctions/open_auction/initial
-where $p/profile/@income > 5000 * exactly-one($i/text())
-return $i
+  for $i in $auction/site/open_auctions/open_auction/initial
+  where $p/profile/@income > 5000 * exactly-one($i/text())
+  return $i
 where $p/profile/@income > 50000
 return <items person="{$p/profile/@income}">{count($l)}</items>
 


Follow ups