~juan457/+junk/zorba

« back to all changes in this revision

Viewing changes to src/store/naive/simple_index_general.cpp

  • Committer: Tarmac
  • Author(s): Markos Zaharioudakis
  • Date: 2012-07-12 17:29:55 UTC
  • mfrom: (10870.4.9 index-maintenance)
  • Revision ID: tarmac-20120712172955-zju6u2p3v102mg43
Incremental maintenance for general indexes. Approved: Markos Zaharioudakis

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
/******************************************************************************
157
157
 
158
158
*******************************************************************************/
 
159
bool GeneralIndexValue::removeNode(const store::Item_t& node)
 
160
{
 
161
  GeneralIndexValue::iterator ite = theNodes.begin();
 
162
  GeneralIndexValue::iterator end = theNodes.end();
 
163
 
 
164
  for (; ite != end; ++ite)
 
165
  {
 
166
    if ((*ite).theNode == node)
 
167
    {
 
168
      theNodes.erase(ite);
 
169
      return true;
 
170
    }
 
171
  }
 
172
 
 
173
  return false;
 
174
}
 
175
 
 
176
 
 
177
/******************************************************************************
 
178
 
 
179
*******************************************************************************/
159
180
void GeneralIndexValue::addNode(store::Item_t& node, bool untyped)
160
181
{
161
182
  csize numNodes = theNodes.size();
191
212
  IndexImpl(qname, spec),
192
213
  theKeyTypeCode(store::XS_LAST),
193
214
  theCompFunction(spec.theTimezone, spec.theCollations[0]),
194
 
  theUntypedFlag(false),
195
 
  theMultiKeyFlag(false)
 
215
  theNumUntypedEntries(0),
 
216
  theNumMultiKeyNodes(0)
196
217
{
197
218
  store::Item* typeName = spec.theKeyTypes[0].getp();
198
219
 
216
237
/******************************************************************************
217
238
 
218
239
*******************************************************************************/
219
 
const XQPCollator* GeneralIndex::getCollator(ulong i) const
 
240
const XQPCollator* GeneralIndex::getCollator(csize i) const
220
241
{
221
242
  ZORBA_ASSERT(i == 0);
222
243
  return theCompFunction.getCollator();
226
247
/******************************************************************************
227
248
 
228
249
*******************************************************************************/
229
 
ulong GeneralIndex::size() const
 
250
csize GeneralIndex::size() const
230
251
{
231
252
  assert(false);
232
253
  return 0;
348
369
  {
349
370
    // try lossless cast to xs:long
350
371
    keyItem->castToLong(castItem);
 
372
 
351
373
    if (castItem != NULL)
352
374
    {
353
375
      keyItem = static_cast<AtomicItem*>(castItem.getp());
363
385
    if (lossy)
364
386
    {
365
387
      node2 = node;
366
 
      found = found || insertInMap(castItem, node2, store::XS_DECIMAL, false);
 
388
      if (insertInMap(castItem, node2, store::XS_DECIMAL, false))
 
389
        found = true;
367
390
    }
368
391
 
369
392
    return found;
389
412
 
390
413
      if (lossy)
391
414
      {
 
415
        /*
 
416
        std::cout << "Lossy LONG insertion in index" << getName()->getStringValue()
 
417
                  << std::endl
 
418
                  << "long value = " << longValue
 
419
                  << " double value = " << castItem->getDoubleValue()
 
420
                  << std::endl << std::endl;
 
421
        */
392
422
        node2 = node;
393
423
        found = insertInMap(key, node2, store::XS_LONG, false);
394
424
 
395
 
        found = found || insertInMap(castItem, node, store::XS_DOUBLE, false);
 
425
        if (insertInMap(castItem, node, store::XS_DOUBLE, false))
 
426
          found = true;
396
427
      }
397
428
      else
398
429
      {
440
471
      xs_long longValue = longItem->getLongValue();
441
472
 
442
473
      node2 = node;
443
 
      found = found || insertInMap(castItem, node2, store::XS_LONG, true);
 
474
      if (insertInMap(castItem, node2, store::XS_LONG, true))
 
475
        found = true;
444
476
 
445
477
      if (longValue > theMaxLong || longValue < theMinLong)
446
478
      {
458
490
        if (lossy)
459
491
        {
460
492
          node2 = node;
461
 
          found = found || insertInMap(castItem, node2, store::XS_DOUBLE, true);
 
493
          if (insertInMap(castItem, node2, store::XS_DOUBLE, true))
 
494
            found = true;
462
495
        }
463
496
      }
464
497
 
468
501
        if (untypedItem->castToGYear(castItem))
469
502
        {
470
503
          node2 = node;
471
 
          found = found || insertInMap(castItem, node2, store::XS_GYEAR, true);
 
504
          if (insertInMap(castItem, node2, store::XS_GYEAR, true))
 
505
            found = true;
472
506
        }
473
507
 
474
508
        if (untypedItem->castToHexBinary(castItem))
475
509
        {
476
510
          node2 = node;
477
 
          found = found || insertInMap(castItem, node2, store::XS_HEXBINARY, true);
 
511
          if (insertInMap(castItem, node2, store::XS_HEXBINARY, true))
 
512
            found = true;
478
513
        }
479
514
 
480
515
        if (untypedItem->castToBase64Binary(castItem))
481
516
        {
482
517
          node2 = node;
483
 
          found = found || insertInMap(castItem, node2, store::XS_BASE64BINARY, true);
 
518
          if (insertInMap(castItem, node2, store::XS_BASE64BINARY, true))
 
519
            found = true;
484
520
        }
485
521
      }
486
522
    }
494
530
      decimalItem->coerceToDouble(castItem, true, lossy);
495
531
 
496
532
      node2 = node;
497
 
      found = found || insertInMap(castItem, node2, store::XS_DOUBLE, true);
 
533
      if (insertInMap(castItem, node2, store::XS_DOUBLE, true))
 
534
        found = true;
498
535
 
499
536
      if (lossy)
500
537
      {
501
538
        castItem.transfer(decimalItem);
502
539
        node2 = node;
503
 
        found = found || insertInMap(castItem, node2, store::XS_DECIMAL, true);
 
540
        if (insertInMap(castItem, node2, store::XS_DECIMAL, true))
 
541
          found = true;
504
542
      }
505
543
 
506
544
      // may also be hexBinary or base64Binary
509
547
        if (untypedItem->castToHexBinary(castItem))
510
548
        {
511
549
          node2 = node;
512
 
          found = found || insertInMap(castItem, node2, store::XS_HEXBINARY, true);
 
550
          if (insertInMap(castItem, node2, store::XS_HEXBINARY, true))
 
551
            found = true;
513
552
        }
514
553
 
515
554
        if (untypedItem->castToBase64Binary(castItem))
516
555
        {
517
556
          node2 = node;
518
 
          found = found || insertInMap(castItem, node2, store::XS_BASE64BINARY, true);
 
557
          if (insertInMap(castItem, node2, store::XS_BASE64BINARY, true))
 
558
            found = true;
519
559
        }
520
560
      }
521
561
    }
524
564
    else if (untypedItem->castToDouble(castItem))
525
565
    {
526
566
      node2 = node;
527
 
      found = found || insertInMap(castItem, node2, store::XS_DOUBLE, true);
 
567
      if (insertInMap(castItem, node2, store::XS_DOUBLE, true))
 
568
        found = true;
528
569
    }
529
570
 
530
571
    // try casting to xs:datetime
531
572
    else if (untypedItem->castToDateTime(castItem))
532
573
    {
533
574
      node2 = node;
534
 
      found = found || insertInMap(castItem, node2, store::XS_DATETIME, true);
 
575
      if (insertInMap(castItem, node2, store::XS_DATETIME, true))
 
576
        found = true;
535
577
    }
536
578
 
537
579
    // try casting to xs:date
538
580
    else if (untypedItem->castToDate(castItem))
539
581
    {
540
582
      node2 = node;
541
 
      found = found || insertInMap(castItem, node2, store::XS_DATE, true);
 
583
      if (insertInMap(castItem, node2, store::XS_DATE, true))
 
584
        found = true;
542
585
    }
543
586
 
544
587
    // try casting to xs:time
545
588
    else if (untypedItem->castToTime(castItem))
546
589
    {
547
590
      node2 = node;
548
 
      found = found || insertInMap(castItem, node2, store::XS_TIME, true);
 
591
      if (insertInMap(castItem, node2, store::XS_TIME, true))
 
592
        found = true;
549
593
    }
550
594
 
551
595
    // try casting to xs:gYearMonth
552
596
    if (!sorted && untypedItem->castToGYearMonth(castItem))
553
597
    {
554
598
      node2 = node;
555
 
      found = found || insertInMap(castItem, node2, store::XS_GYEAR_MONTH, true);
 
599
      if (insertInMap(castItem, node2, store::XS_GYEAR_MONTH, true))
 
600
        found = true;
556
601
    }
557
602
 
558
603
    // try casting to xs:gMonthDay
559
604
    else if (!sorted && untypedItem->castToGMonthDay(castItem))
560
605
    {
561
606
      node2 = node;
562
 
      found = found || insertInMap(castItem, node2, store::XS_GMONTH_DAY, true);
 
607
      if (insertInMap(castItem, node2, store::XS_GMONTH_DAY, true))
 
608
        found = true;
563
609
    }
564
610
 
565
611
    // try casting to xs:gDay
566
612
    else if (!sorted && untypedItem->castToGDay(castItem))
567
613
    {
568
614
      node2 = node;
569
 
      found = found || insertInMap(castItem, node2, store::XS_GDAY, true);
 
615
      if (insertInMap(castItem, node2, store::XS_GDAY, true))
 
616
        found = true;
570
617
    }
571
618
 
572
619
    // try casting to xs:gMonth
573
620
    else if (!sorted && untypedItem->castToGMonth(castItem))
574
621
    {
575
622
      node2 = node;
576
 
      found = found || insertInMap(castItem, node2, store::XS_GMONTH, true);
 
623
      if (insertInMap(castItem, node2, store::XS_GMONTH, true))
 
624
        found = true;
577
625
    }
578
626
 
579
627
    // try casting to xs:duration
580
628
    else if (untypedItem->castToDuration(castItem))
581
629
    {
582
630
      node2 = node;
583
 
      found = found || insertInMap(castItem, node2, store::XS_DURATION, true);
 
631
      if (insertInMap(castItem, node2, store::XS_DURATION, true))
 
632
        found = true;
584
633
    }
585
634
 
586
635
    // try casting to xs:hexBinary
587
636
    else if (!sorted && untypedItem->castToHexBinary(castItem))
588
637
    {
589
638
      node2 = node;
590
 
      found = found || insertInMap(castItem, node2, store::XS_HEXBINARY, true);
 
639
      if (insertInMap(castItem, node2, store::XS_HEXBINARY, true))
 
640
        found = true;
591
641
    }
592
642
 
593
643
    // try casting to xs:base64Binary
594
644
    else if (!sorted && untypedItem->castToBase64Binary(castItem))
595
645
    {
596
646
      node2 = node;
597
 
      found = found || insertInMap(castItem, node2, store::XS_BASE64BINARY, true);
 
647
      if (insertInMap(castItem, node2, store::XS_BASE64BINARY, true))
 
648
        found = true;
598
649
    }
599
650
 
600
651
    return found;
620
671
    bool untyped)
621
672
{
622
673
  if (untyped)
623
 
    theUntypedFlag = true;
624
 
 
625
 
  if (isSorted())
626
 
  {
627
 
    GeneralTreeIndex* idx = static_cast<GeneralTreeIndex*>(this);
628
 
    return idx->insertInMap(key, node, idx->theMaps[targetMap], untyped);
629
 
  }
630
 
  else
631
 
  {
632
 
    GeneralHashIndex* idx = static_cast<GeneralHashIndex*>(this);
633
 
    return idx->insertInMap(key, node, idx->theMaps[targetMap], untyped);
 
674
    ++theNumUntypedEntries;
 
675
 
 
676
  if (isSorted())
 
677
  {
 
678
    GeneralTreeIndex* idx = static_cast<GeneralTreeIndex*>(this);
 
679
    return idx->insertInMap(key, node, idx->theMaps[targetMap], untyped);
 
680
  }
 
681
  else
 
682
  {
 
683
    GeneralHashIndex* idx = static_cast<GeneralHashIndex*>(this);
 
684
    return idx->insertInMap(key, node, idx->theMaps[targetMap], untyped);
 
685
  }
 
686
}
 
687
 
 
688
 
 
689
/******************************************************************************
 
690
 
 
691
*******************************************************************************/
 
692
bool GeneralIndex::remove(const store::Item_t& key, const store::Item_t& node)
 
693
{
 
694
  bool lossy = false;
 
695
  bool found = false;
 
696
  store::Item_t castItem;
 
697
 
 
698
  bool sorted = isSorted();
 
699
 
 
700
  AtomicItem* keyItem = static_cast<AtomicItem*>(key.getp());
 
701
 
 
702
  if (keyItem == NULL)
 
703
  {
 
704
    std::vector<store::Item_t>::iterator ite =
 
705
    std::find(theEmptyKeyNodes.begin(), theEmptyKeyNodes.end(), node);
 
706
 
 
707
    ZORBA_ASSERT(ite != theEmptyKeyNodes.end());
 
708
 
 
709
    theEmptyKeyNodes.erase(ite);
 
710
    return true;
 
711
  }
 
712
 
 
713
  if (keyItem->getBaseItem() != NULL)
 
714
  {
 
715
    keyItem = static_cast<AtomicItem*>(keyItem->getBaseItem());
 
716
  }
 
717
 
 
718
  if (isTyped())
 
719
  {
 
720
    return removeFromMap(key, node, theKeyTypeCode, false);
 
721
  }
 
722
 
 
723
  store::SchemaTypeCode keyType = keyItem->getTypeCode();
 
724
 
 
725
  switch (keyType)
 
726
  {
 
727
  case store::XS_BASE64BINARY:
 
728
  case store::XS_HEXBINARY:
 
729
 
 
730
  case store::XS_QNAME:
 
731
  case store::XS_NOTATION:
 
732
 
 
733
  case store::XS_GYEAR_MONTH:
 
734
  case store::XS_GYEAR:
 
735
  case store::XS_GMONTH_DAY:
 
736
  case store::XS_GDAY:
 
737
  case store::XS_GMONTH:
 
738
  {
 
739
    assert(!sorted);
 
740
    // falth through
 
741
  }
 
742
 
 
743
  case store::XS_ANY_URI:
 
744
 
 
745
  case store::XS_BOOLEAN:
 
746
 
 
747
  case store::XS_DATETIME:
 
748
  case store::XS_DATE:
 
749
  case store::XS_TIME:
 
750
  {
 
751
    return removeFromMap(key, node, keyType, false);
 
752
  }
 
753
 
 
754
  case store::XS_DURATION:
 
755
  case store::XS_YM_DURATION:
 
756
  case store::XS_DT_DURATION:
 
757
  {
 
758
    return removeFromMap(key, node, store::XS_DURATION, false);
 
759
  }
 
760
 
 
761
  case store::XS_STRING:
 
762
  case store::XS_NORMALIZED_STRING:
 
763
  case store::XS_TOKEN:
 
764
  case store::XS_NMTOKEN:
 
765
  case store::XS_LANGUAGE:
 
766
  case store::XS_NAME:
 
767
  case store::XS_NCNAME:
 
768
  case store::XS_ID:
 
769
  case store::XS_IDREF:
 
770
  case store::XS_ENTITY:
 
771
  {
 
772
    return removeFromMap(key, node, store::XS_STRING, false);
 
773
  }
 
774
 
 
775
  case store::XS_DOUBLE:
 
776
  case store::XS_FLOAT:
 
777
  {
 
778
    return removeFromMap(key, node, store::XS_DOUBLE, false);
 
779
  }
 
780
 
 
781
  case store::XS_DECIMAL:
 
782
  case store::XS_INTEGER:
 
783
  case store::XS_NON_POSITIVE_INTEGER:
 
784
  case store::XS_NEGATIVE_INTEGER:
 
785
  case store::XS_NON_NEGATIVE_INTEGER:
 
786
  case store::XS_POSITIVE_INTEGER:
 
787
  case store::XS_UNSIGNED_LONG:
 
788
  {
 
789
    // try lossless cast to xs:long
 
790
    keyItem->castToLong(castItem);
 
791
 
 
792
    if (castItem != NULL)
 
793
    {
 
794
      keyItem = static_cast<AtomicItem*>(castItem.getp());
 
795
      goto longmap;
 
796
    }
 
797
 
 
798
    // Coerce to xs:double 
 
799
    keyItem->coerceToDouble(castItem, true, lossy);
 
800
 
 
801
    found = removeFromMap(key, node, store::XS_DOUBLE, false);
 
802
 
 
803
    if (lossy)
 
804
    {
 
805
      if (removeFromMap(castItem, node, store::XS_DECIMAL, false))
 
806
        found = true;
 
807
    }
 
808
 
 
809
    return found;
 
810
  }
 
811
 
 
812
  case store::XS_LONG:
 
813
  {
 
814
    // NOTE: here we use KeyItem, instead of key, as arg to removeFromMap, because
 
815
    // we can reach here from the store::XS_DECIMAL case.
 
816
longmap:
 
817
    xs_long longValue = static_cast<LongItem*>(keyItem)->getLongValue();
 
818
 
 
819
    if (longValue > theMaxLong || longValue < theMinLong)
 
820
    {
 
821
      if (sorted)
 
822
      {
 
823
        lossy = true;
 
824
        xs_double doubleValue(longValue);
 
825
        GET_FACTORY().createDouble(castItem, doubleValue);
 
826
      }
 
827
      else
 
828
      {
 
829
        keyItem->coerceToDouble(castItem, false, lossy);
 
830
      }
 
831
 
 
832
      if (lossy)
 
833
      {
 
834
        /*
 
835
        std::cout << "Lossy LONG insertion in index" << getName()->getStringValue()
 
836
                  << std::endl
 
837
                  << "long value = " << longValue
 
838
                  << " double value = " << castItem->getDoubleValue()
 
839
                  << std::endl << std::endl;
 
840
        */
 
841
        found = removeFromMap(keyItem, node, store::XS_LONG, false);
 
842
 
 
843
        if (removeFromMap(castItem, node, store::XS_DOUBLE, false))
 
844
          found = true;
 
845
      }
 
846
      else
 
847
      {
 
848
        found = removeFromMap(keyItem, node, store::XS_LONG, false);
 
849
      }
 
850
    }
 
851
    else
 
852
    {
 
853
      found = removeFromMap(keyItem, node, store::XS_LONG, false);
 
854
    }
 
855
 
 
856
    return found;
 
857
  }
 
858
 
 
859
  case store::XS_INT:
 
860
  case store::XS_SHORT:
 
861
  case store::XS_BYTE:
 
862
  case store::XS_UNSIGNED_INT:
 
863
  case store::XS_UNSIGNED_SHORT:
 
864
  case store::XS_UNSIGNED_BYTE:
 
865
  {
 
866
    return removeFromMap(key, node, store::XS_LONG, false);
 
867
  }
 
868
 
 
869
  case store::XS_UNTYPED_ATOMIC:
 
870
  {
 
871
    store::ItemHandle<UntypedAtomicItem> untypedItem = 
 
872
    static_cast<UntypedAtomicItem*>(key.getp());
 
873
 
 
874
    // cast to xs:string
 
875
    untypedItem->castToString(castItem);
 
876
 
 
877
    found = removeFromMap(castItem, node, store::XS_STRING, false);
 
878
 
 
879
    // try casting to xs:long
 
880
    if (untypedItem->castToLong(castItem))
 
881
    {
 
882
      store::ItemHandle<LongItem> longItem = static_cast<LongItem*>(castItem.getp());
 
883
 
 
884
      xs_long longValue = longItem->getLongValue();
 
885
 
 
886
      if (removeFromMap(castItem, node, store::XS_LONG, true))
 
887
        found = true;
 
888
 
 
889
      if (longValue > theMaxLong || longValue < theMinLong)
 
890
      {
 
891
        if (sorted)
 
892
        {
 
893
          lossy = true;
 
894
          xs_double doubleValue(longValue);
 
895
          GET_FACTORY().createDouble(castItem, doubleValue);
 
896
        }
 
897
        else
 
898
        {
 
899
          longItem->coerceToDouble(castItem, false, lossy);
 
900
        }
 
901
 
 
902
        if (lossy)
 
903
        {
 
904
          if (removeFromMap(castItem, node, store::XS_DOUBLE, true))
 
905
            found = true;
 
906
        }
 
907
      }
 
908
 
 
909
      // may also be gYear, hexBinary, base64Binary, or boolean
 
910
      if (!sorted)
 
911
      {
 
912
        if (untypedItem->castToGYear(castItem))
 
913
        {
 
914
          if (removeFromMap(castItem, node, store::XS_GYEAR, true))
 
915
            found = true;
 
916
        }
 
917
 
 
918
        if (untypedItem->castToHexBinary(castItem))
 
919
        {
 
920
          if (removeFromMap(castItem, node, store::XS_HEXBINARY, true))
 
921
            found = true;
 
922
        }
 
923
 
 
924
        if (untypedItem->castToBase64Binary(castItem))
 
925
        {
 
926
          if (removeFromMap(castItem, node, store::XS_BASE64BINARY, true))
 
927
            found = true;
 
928
        }
 
929
      }
 
930
    }
 
931
 
 
932
    // try casting to xs:decimal
 
933
    else if (untypedItem->castToDecimal(castItem))
 
934
    {
 
935
      store::ItemHandle<DecimalItem> decimalItem = 
 
936
      static_cast<DecimalItem*>(castItem.getp());
 
937
 
 
938
      decimalItem->coerceToDouble(castItem, true, lossy);
 
939
 
 
940
      if (removeFromMap(castItem, node, store::XS_DOUBLE, true))
 
941
        found = true;
 
942
 
 
943
      if (lossy)
 
944
      {
 
945
        castItem.transfer(decimalItem);
 
946
        if (removeFromMap(castItem, node, store::XS_DECIMAL, true))
 
947
          found = true;
 
948
      }
 
949
 
 
950
      // may also be hexBinary or base64Binary
 
951
      if (sorted)
 
952
      {
 
953
        if (untypedItem->castToHexBinary(castItem))
 
954
        {
 
955
          if (removeFromMap(castItem, node, store::XS_HEXBINARY, true))
 
956
            found = true;
 
957
        }
 
958
 
 
959
        if (untypedItem->castToBase64Binary(castItem))
 
960
        {
 
961
          if (removeFromMap(castItem, node, store::XS_BASE64BINARY, true))
 
962
            found = true;
 
963
        }
 
964
      }
 
965
    }
 
966
 
 
967
    // try casting to xs:double
 
968
    else if (untypedItem->castToDouble(castItem))
 
969
    {
 
970
      if (removeFromMap(castItem, node, store::XS_DOUBLE, true))
 
971
        found = true;
 
972
    }
 
973
 
 
974
    // try casting to xs:datetime
 
975
    else if (untypedItem->castToDateTime(castItem))
 
976
    {
 
977
      if (removeFromMap(castItem, node, store::XS_DATETIME, true))
 
978
        found = true;
 
979
    }
 
980
 
 
981
    // try casting to xs:date
 
982
    else if (untypedItem->castToDate(castItem))
 
983
    {
 
984
      if (removeFromMap(castItem, node, store::XS_DATE, true))
 
985
        found = true;
 
986
    }
 
987
 
 
988
    // try casting to xs:time
 
989
    else if (untypedItem->castToTime(castItem))
 
990
    {
 
991
      if (removeFromMap(castItem, node, store::XS_TIME, true))
 
992
        found = true;
 
993
    }
 
994
 
 
995
    // try casting to xs:gYearMonth
 
996
    if (!sorted && untypedItem->castToGYearMonth(castItem))
 
997
    {
 
998
      if (removeFromMap(castItem, node, store::XS_GYEAR_MONTH, true))
 
999
        found = true;
 
1000
    }
 
1001
 
 
1002
    // try casting to xs:gMonthDay
 
1003
    else if (!sorted && untypedItem->castToGMonthDay(castItem))
 
1004
    {
 
1005
      if (removeFromMap(castItem, node, store::XS_GMONTH_DAY, true))
 
1006
        found = true;
 
1007
    }
 
1008
 
 
1009
    // try casting to xs:gDay
 
1010
    else if (!sorted && untypedItem->castToGDay(castItem))
 
1011
    {
 
1012
      if (removeFromMap(castItem, node, store::XS_GDAY, true))
 
1013
        found = true;
 
1014
    }
 
1015
 
 
1016
    // try casting to xs:gMonth
 
1017
    else if (!sorted && untypedItem->castToGMonth(castItem))
 
1018
    {
 
1019
      if (removeFromMap(castItem, node, store::XS_GMONTH, true))
 
1020
        found = true;
 
1021
    }
 
1022
 
 
1023
    // try casting to xs:duration
 
1024
    else if (untypedItem->castToDuration(castItem))
 
1025
    {
 
1026
      if (removeFromMap(castItem, node, store::XS_DURATION, true))
 
1027
        found = true;
 
1028
    }
 
1029
 
 
1030
    // try casting to xs:hexBinary
 
1031
    else if (!sorted && untypedItem->castToHexBinary(castItem))
 
1032
    {
 
1033
      if (removeFromMap(castItem, node, store::XS_HEXBINARY, true))
 
1034
        found = true;
 
1035
    }
 
1036
 
 
1037
    // try casting to xs:base64Binary
 
1038
    else if (!sorted && untypedItem->castToBase64Binary(castItem))
 
1039
    {
 
1040
      if (removeFromMap(castItem, node, store::XS_BASE64BINARY, true))
 
1041
        found = true;
 
1042
    }
 
1043
 
 
1044
    return found;
 
1045
  }
 
1046
 
 
1047
  default:
 
1048
    ZORBA_ASSERT(false);
 
1049
  }
 
1050
 
 
1051
  return true;
 
1052
}
 
1053
 
 
1054
 
 
1055
/******************************************************************************
 
1056
 
 
1057
*******************************************************************************/
 
1058
bool GeneralIndex::remove(
 
1059
    const store::IndexKey* key,
 
1060
    const store::Item_t& node,
 
1061
    bool all)
 
1062
{
 
1063
  ZORBA_ASSERT(false);
 
1064
}
 
1065
 
 
1066
 
 
1067
/******************************************************************************
 
1068
 
 
1069
*******************************************************************************/
 
1070
bool GeneralIndex::removeFromMap(
 
1071
    const store::Item_t& key,
 
1072
    const store::Item_t& node,
 
1073
    store::SchemaTypeCode targetMap,
 
1074
    bool untyped)
 
1075
{
 
1076
  if (untyped)
 
1077
    --theNumUntypedEntries;
 
1078
 
 
1079
  if (isSorted())
 
1080
  {
 
1081
    GeneralTreeIndex* idx = static_cast<GeneralTreeIndex*>(this);
 
1082
    return idx->removeFromMap(key, node, idx->theMaps[targetMap]);
 
1083
  }
 
1084
  else
 
1085
  {
 
1086
    GeneralHashIndex* idx = static_cast<GeneralHashIndex*>(this);
 
1087
    return idx->removeFromMap(key, node, idx->theMaps[targetMap]);
634
1088
  }
635
1089
}
636
1090
 
670
1124
*******************************************************************************/
671
1125
GeneralHashIndex::~GeneralHashIndex()
672
1126
{
673
 
  for (ulong i = 0; i < store::XS_LAST; ++i)
 
1127
  for (csize i = 0; i < store::XS_LAST; ++i)
674
1128
  {
675
1129
    if (theMaps[i] == NULL)
676
1130
      continue;
745
1199
/******************************************************************************
746
1200
 
747
1201
*******************************************************************************/
748
 
bool GeneralHashIndex::remove(
 
1202
bool GeneralHashIndex::removeFromMap(
749
1203
    const store::Item_t& key,
750
 
    const store::Item_t& item,
751
 
    bool all)
 
1204
    const store::Item_t& node,
 
1205
    IndexMap* targetMap)
752
1206
{
753
 
  assert(false);
 
1207
  assert(targetMap);
 
1208
  assert(key != NULL);
 
1209
 
 
1210
  IndexMap::iterator pos = targetMap->find(key);
 
1211
 
 
1212
  if (pos != targetMap->end())
 
1213
  {
 
1214
    GeneralIndexValue* valueSet = (*pos).second;
 
1215
 
 
1216
    bool found = valueSet->removeNode(node);
 
1217
 
 
1218
    if (valueSet->empty())
 
1219
    {
 
1220
      const_cast<store::Item*>((*pos).first)->removeReference();
 
1221
      delete valueSet;
 
1222
      targetMap->erase(pos);
 
1223
    }
 
1224
 
 
1225
    return found;
 
1226
  }
 
1227
 
754
1228
  return false;
755
1229
}
756
1230
 
760
1234
*******************************************************************************/
761
1235
void GeneralHashIndex::clear()
762
1236
{
763
 
  for (ulong i = 0; i < store::XS_LAST; ++i)
 
1237
  for (csize i = 0; i < store::XS_LAST; ++i)
764
1238
  {
765
1239
    if (theMaps[i] == NULL)
766
1240
      continue;
853
1327
*******************************************************************************/
854
1328
GeneralTreeIndex::~GeneralTreeIndex()
855
1329
{
856
 
  for (ulong i = 0; i < store::XS_LAST; ++i)
 
1330
  for (csize i = 0; i < store::XS_LAST; ++i)
857
1331
  {
858
1332
    if (theMaps[i] == NULL)
859
1333
      continue;
920
1394
/******************************************************************************
921
1395
 
922
1396
*******************************************************************************/
923
 
bool GeneralTreeIndex::remove(
 
1397
bool GeneralTreeIndex::removeFromMap(
924
1398
    const store::Item_t& key,
925
 
    const store::Item_t& item,
926
 
    bool all)
 
1399
    const store::Item_t& node,
 
1400
    IndexMap* targetMap)
927
1401
{
928
 
  return true;
 
1402
  assert(targetMap);
 
1403
  assert(key != NULL);
 
1404
 
 
1405
  IndexMap::iterator pos = targetMap->find(key);
 
1406
 
 
1407
  if (pos != targetMap->end())
 
1408
  {
 
1409
    GeneralIndexValue* valueSet = (*pos).second;
 
1410
 
 
1411
    bool found = valueSet->removeNode(node);
 
1412
 
 
1413
    if (valueSet->empty())
 
1414
    {
 
1415
      const_cast<store::Item*>((*pos).first)->removeReference();
 
1416
      delete valueSet;
 
1417
      targetMap->erase(pos);
 
1418
    }
 
1419
 
 
1420
    return found;
 
1421
  }
 
1422
 
 
1423
  return false;
929
1424
}
930
1425
 
931
1426
 
934
1429
*******************************************************************************/
935
1430
void GeneralTreeIndex::clear()
936
1431
{
937
 
  for (ulong i = 0; i < store::XS_LAST; ++i)
 
1432
  for (csize i = 0; i < store::XS_LAST; ++i)
938
1433
  {
939
1434
    if (theMaps[i] == NULL)
940
1435
      continue;
1123
1618
  if (theProbeKind == store::IndexCondition::POINT_VALUE ||
1124
1619
      theProbeKind == store::IndexCondition::BOX_VALUE)
1125
1620
  {
1126
 
    if (theIndex->theMultiKeyFlag)
 
1621
    if (theIndex->theNumMultiKeyNodes > 0)
1127
1622
    {
1128
1623
      RAISE_ERROR_NO_LOC(err::XPTY0004,
1129
1624
      ERROR_PARAMS(ZED(NoMultiKeyNodeValues_2), theIndex->getName()->getStringValue()));
1130
1625
    }
1131
1626
 
1132
 
    if (theIndex->theUntypedFlag)
 
1627
    if (theIndex->theNumUntypedEntries > 0)
1133
1628
    {
1134
1629
      checkStringKeyType(theCondition->theKey.getp());
1135
1630
      checkStringKeyType(theCondition->theLowerBound.getp());
1871
2366
  {
1872
2367
    theIsFullProbe = true;
1873
2368
 
1874
 
    for (ulong i = 0; i < store::XS_LAST; ++i)
 
2369
    for (csize i = 0; i < store::XS_LAST; ++i)
1875
2370
    {
1876
2371
      if (idx->theMaps[i] == NULL)
1877
2372
        continue;