Merge lp:~zorba-coders/zorba/feature-transient_maps into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Matthias Brantner
Approved revision: 10851
Merged at revision: 10888
Proposed branch: lp:~zorba-coders/zorba/feature-transient_maps
Merge into: lp:zorba
Diff against target: 1867 lines (+875/-213)
26 files modified
ChangeLog (+1/-0)
modules/com/zorba-xquery/www/modules/store/data-structures/unordered-map.xq (+74/-30)
src/context/dynamic_context.cpp (+69/-0)
src/context/dynamic_context.h (+10/-0)
src/functions/pregenerated/func_maps.cpp (+45/-0)
src/functions/pregenerated/func_maps.h (+36/-0)
src/functions/pregenerated/function_enum.h (+2/-0)
src/runtime/pregenerated/iterator_enum.h (+2/-0)
src/runtime/spec/store/maps.xml (+65/-5)
src/runtime/store/maps_impl.cpp (+302/-156)
src/runtime/store/pregenerated/maps.cpp (+56/-0)
src/runtime/store/pregenerated/maps.h (+66/-1)
src/runtime/visitors/pregenerated/planiter_visitor.h (+10/-0)
src/runtime/visitors/pregenerated/printer_visitor.cpp (+28/-0)
src/runtime/visitors/pregenerated/printer_visitor.h (+6/-0)
src/store/api/index.h (+5/-0)
src/store/api/store.h (+4/-0)
src/store/naive/pul_primitives.cpp (+6/-7)
src/store/naive/simple_index_general.cpp (+2/-2)
src/store/naive/simple_index_general.h (+26/-3)
src/store/naive/store.cpp (+5/-5)
src/store/naive/store.h (+4/-4)
test/rbkt/ExpQueryResults/zorba/store/unordered-map/map7.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/store/unordered-map/transient-map0.xml.res (+1/-0)
test/rbkt/Queries/zorba/store/unordered-map/map7.xq (+22/-0)
test/rbkt/Queries/zorba/store/unordered-map/transient-map0.xq (+27/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/feature-transient_maps
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Till Westmann Approve
Review via email: mp+106287@code.launchpad.net

Commit message

Added support for transient maps in the unordered-maps module.

Description of the change

Added support for transient maps in the unordered-maps module.

A transient map is only available within the execution of the currently active XQuery program. It is not available to any other program that is running in parallel or after the program that created it.

Transient maps can be created using map:create-transient. All other functions are left unchanged and operate on transient and non-transient/persistent maps. Transient and persistent maps can not have the same names.

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/feature-transient_maps into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job feature-transient_maps-2012-05-18T00-03-10.458Z is
  finished. The final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-transient_maps-2012-05-18T00-27-10.419Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 2 Pending.

Revision history for this message
Till Westmann (tillw) wrote :

The docs say that a key can consist of a "set" of atomic values. As the order of the values is relevant "list" or "tuple" might be better.

As the parameters for insert, get, etc. are anyAtomicType? an empty sequence can be passed in, but the doc does not say how that is handled.

I've extended the test to cover a little more of the functionality.

review: Needs Fixing
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in ChangeLog

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-transient_maps-2012-06-20T18-41-00.67Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Needs Fixing, 1 Pending.

Revision history for this message
Till Westmann (tillw) wrote :

Modified the documentation and added another test.

Unfortunately this test (zorba/store/unordered-map/map7.xq) crashes (SEGV).

review: Needs Fixing
Revision history for this message
Till Westmann (tillw) wrote :

Fixed the crashing test and addressed all of my review comments.

review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-transient_maps-2012-06-23T00-39-00.771Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-transient_maps-2012-06-23T01-25-57.278Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2012-06-22 08:38:46 +0000
+++ ChangeLog 2012-06-23 00:29:20 +0000
@@ -5,6 +5,7 @@
55
6New Features:6New Features:
7 * Implemented latest W3C soec for group by clause7 * Implemented latest W3C soec for group by clause
8 * Added support for transient maps to the http://www.zorba-xquery.com/modules/store/data-structures/unordered-map module.
89
9Optimizations:10Optimizations:
10 * Small optimization of comparison operations.11 * Small optimization of comparison operations.
1112
=== modified file 'modules/com/zorba-xquery/www/modules/store/data-structures/unordered-map.xq'
--- modules/com/zorba-xquery/www/modules/store/data-structures/unordered-map.xq 2012-06-18 10:06:47 +0000
+++ modules/com/zorba-xquery/www/modules/store/data-structures/unordered-map.xq 2012-06-23 00:29:20 +0000
@@ -1,7 +1,6 @@
1xquery version "3.0";1xquery version "3.0";
2
3(:2(:
4 : Copyright 2006-2009 The FLWOR Foundation.3 : Copyright 2006-2012 The FLWOR Foundation.
5 :4 :
6 : Licensed under the Apache License, Version 2.0 (the "License");5 : Licensed under the Apache License, Version 2.0 (the "License");
7 : you may not use this file except in compliance with the License.6 : you may not use this file except in compliance with the License.
@@ -17,17 +16,20 @@
17:)16:)
1817
19(:~18(:~
20 : This module defines a set of functions for working with19 : <p>This module defines a set of functions for working with maps. A map
21 : maps. A map is identified by a QName and can20 : is identified by a QName and can be created using the map:create or
22 : be created using the map:create function and deleted21 : map:create-transient functions and deleted using the map:delete function,
23 : using the map:delete function, respectively. However, its22 : respectively.</p>
24 : actual lifetime depends on the particular store implementation.23 :
25 :24 : <p>The lifetime of a transient map is limited by the execution of the
26 : The key of a particular entry in the map can consist25 : current XQuery program. A non-transient (or persistent) map lives until
27 : out of a set of atomic values (called attributes).26 : it is explicitly deleted. Accordingly, it's also available
28 : The actual type of each attribute can be determined when the27 : to other XQuery programs.</p>
29 : map is created. The value can be an arbitrary sequence28 :
30 : of items.29 : <p>The key of a particular entry in the map can consist of a tuple of
30 : atomic values (called attributes). The actual type of each attribute
31 : is determined when the map is created. The value of each attribute can
32 : be an arbitrary sequence of items.</p>
31 :33 :
32 : @see <a href="../../html/data_lifecycle.html">Data Lifecycle</a>34 : @see <a href="../../html/data_lifecycle.html">Data Lifecycle</a>
33 : @see <a href="www.zorba-xquery.com_errors.html">http://www.zorba-xquery.com/errors</a>35 : @see <a href="www.zorba-xquery.com_errors.html">http://www.zorba-xquery.com/errors</a>
@@ -46,11 +48,10 @@
46declare option ver:module-version "2.0";48declare option ver:module-version "2.0";
4749
48(:~50(:~
49 : Create a map with a given name and a set of types for51 : Create a map with a given name and a set of type identifiers for each key
50 : each key attribute. Note that the function is variadic52 : attribute. Note that the function is variadic and might take an arbitrary
51 : and might take an arbitrary amount of types for the key53 : number of type identifiers for the key attributes. Also note that the
52 : attributes. Also note that the function is sequential54 : function is sequential and immediately creates the map in the store.
53 : and immediately creates the map in the store.
54 :55 :
55 : @param $name the name of the map56 : @param $name the name of the map
56 : @param $key-type an arbitrary number of types, one57 : @param $key-type an arbitrary number of types, one
@@ -68,6 +69,26 @@
68 $key-type as xs:QName) as empty-sequence() external;69 $key-type as xs:QName) as empty-sequence() external;
6970
70(:~71(:~
72 : Create a transient map with a given name and a set of type identifiers
73 : for each key attribute. Note that the function is variadic and might
74 : take an arbitrary number of type identifiers for the key attributes.
75 :
76 : @param $name the name of the map
77 : @param $key-type an arbitrary number of types, one
78 : for each key attribute.
79 :
80 : @return the function is sequential and immediately creates
81 : the corresponding map but returns the empty-sequence.
82 :
83 : @error err:XPTY0004 if any of the attribute types is not a subtype of
84 : xs:anyAtomicType.
85 : @error zerr:ZSTR0001 if a map with the given name already exists.
86 :)
87declare %an:variadic %an:sequential function map:create-transient(
88 $name as xs:QName,
89 $key-type as xs:QName) as empty-sequence() external;
90
91(:~
71 : Destroys the map with the given name.92 : Destroys the map with the given name.
72 : 93 :
73 : @param $name the name of the map to delete94 : @param $name the name of the map to delete
@@ -81,13 +102,17 @@
81 $name as xs:QName) as empty-sequence() external;102 $name as xs:QName) as empty-sequence() external;
82103
83(:~104(:~
84 : Inserts a new entry into the map with the given105 : Inserts a new entry into the map with the given name. Note that the
85 : name. Note that the function is variadic106 : function is variadic and might take an arbitrary number of key attributes.
86 : and might take an arbitrary amount of key attributes.107 : If an entry with the given key already exists in the map, the value
87 : If an entry with the given key already exists in the108 : sequences of the existing entry and the sequence passed using $value
88 : map, the value sequences of the existing entry and the109 : argument are concatenated.
89 : sequence passed using $value argument are concatenated.110 :
90 : 111 : Note that it is possible to insert entries with empty key attributes.
112 : However as the getting the entries is based on the "eq" comparison and
113 : as "eq" with an empty sequence always return false, it is not possible
114 : to retrieve these entries.
115 :
91 : @param $name the name of the map116 : @param $name the name of the map
92 : @param $value the value of the entry to insert117 : @param $value the value of the entry to insert
93 : @param $key an arbitrary number of key attributes.118 : @param $key an arbitrary number of key attributes.
@@ -113,8 +138,12 @@
113 $key as xs:anyAtomicType?) as empty-sequence() external;138 $key as xs:anyAtomicType?) as empty-sequence() external;
114139
115(:~140(:~
116 : Returns the value of the entry with the given key141 : Returns the value of the entry with the given key from the map.
117 : from the map.142 :
143 : Note that it is possible to insert entries with empty key attributes.
144 : However as the getting the entries is based on the "eq" comparison and
145 : as "eq" with an empty sequence always return false, it is not possible
146 : to retrieve these entries.
118 :147 :
119 : @param $name the name of the map148 : @param $name the name of the map
120 : @param an arbitrary number of search key attributes.149 : @param an arbitrary number of search key attributes.
@@ -140,6 +169,11 @@
140(:~169(:~
141 : Removes an entry identified by the given key from the map.170 : Removes an entry identified by the given key from the map.
142 :171 :
172 : Note that it is possible to insert entries with empty key attributes.
173 : However as the removing the entries is based on the "eq" comparison and
174 : as "eq" with an empty sequence always return false, it is not possible
175 : to remove these entries.
176 :
143 : @param $name the name of the map177 : @param $name the name of the map
144 : @param an arbitrary number of search key attributes.178 : @param an arbitrary number of search key attributes.
145 :179 :
@@ -156,7 +190,6 @@
156 : specified when creating the map.190 : specified when creating the map.
157 :191 :
158 : @see map:create192 : @see map:create
159 :
160 :)193 :)
161declare %an:variadic %an:sequential function map:remove(194declare %an:variadic %an:sequential function map:remove(
162 $name as xs:QName,195 $name as xs:QName,
@@ -199,8 +232,7 @@
199 :232 :
200 : @error zerr:ZDDY0023 if a map with the given name does not exist.233 : @error zerr:ZDDY0023 if a map with the given name does not exist.
201 :)234 :)
202declare function map:size(235declare function map:size($name as xs:QName) as xs:integer external;
203 $name as xs:QName) as xs:integer external;
204236
205(:~237(:~
206 : The function returns a sequence of QNames of the maps that are238 : The function returns a sequence of QNames of the maps that are
@@ -210,3 +242,15 @@
210 :242 :
211 :)243 :)
212declare function map:available-maps() as xs:QName* external;244declare function map:available-maps() as xs:QName* external;
245
246(:~
247 : The function returns true if the map identified by the given QName
248 : is transient, false otherwise.
249 :
250 : @param $name the name of the map
251 :
252 : @return true if the map is transient, false otherwise.
253 :
254 : @error zerr:ZDDY0023 if a map with the given name does not exist.
255 :)
256declare function map:is-transient($name as xs:QName) as xs:boolean external;
213257
=== modified file 'src/context/dynamic_context.cpp'
--- src/context/dynamic_context.cpp 2012-06-18 10:06:47 +0000
+++ src/context/dynamic_context.cpp 2012-06-23 00:29:20 +0000
@@ -130,6 +130,7 @@
130 theParent(NULL),130 theParent(NULL),
131 keymap(NULL),131 keymap(NULL),
132 theAvailableIndices(NULL),132 theAvailableIndices(NULL),
133 theAvailableMaps(NULL),
133 theEnvironmentVariables(NULL),134 theEnvironmentVariables(NULL),
134 theDocLoadingUserTime(0.0),135 theDocLoadingUserTime(0.0),
135 theDocLoadingTime(0)136 theDocLoadingTime(0)
@@ -175,6 +176,9 @@
175176
176 if (theAvailableIndices)177 if (theAvailableIndices)
177 delete theAvailableIndices;178 delete theAvailableIndices;
179
180 if (theAvailableMaps)
181 delete theAvailableMaps;
178}182}
179183
180184
@@ -728,6 +732,71 @@
728/*******************************************************************************732/*******************************************************************************
729733
730********************************************************************************/734********************************************************************************/
735store::Index* dynamic_context::getMap(store::Item* qname) const
736{
737 if (theAvailableMaps == NULL)
738 return NULL;
739
740 store::Index_t map;
741
742 if (theAvailableMaps->get(qname, map))
743 {
744 return map.getp();
745 }
746 else
747 {
748 return NULL;
749 }
750}
751
752
753/*******************************************************************************
754
755********************************************************************************/
756void dynamic_context::bindMap(
757 store::Item* qname,
758 store::Index_t& map)
759{
760 if (theAvailableMaps == NULL)
761 theAvailableMaps = new IndexMap(HashMapItemPointerCmp(0, NULL), 8, false);
762
763 if (!theAvailableMaps->insert(qname, map))
764 {
765 ZORBA_ASSERT(false);
766 }
767}
768
769
770/*******************************************************************************
771
772********************************************************************************/
773void dynamic_context::unbindMap(store::Item* qname)
774{
775 if (theAvailableMaps != NULL)
776 theAvailableMaps->erase(qname);
777}
778
779
780/*******************************************************************************
781
782********************************************************************************/
783void dynamic_context::getMapNames(std::vector<store::Item_t>& names) const
784{
785 if (theAvailableMaps == NULL)
786 return;
787
788 for (IndexMap::iterator lIter = theAvailableMaps->begin();
789 lIter != theAvailableMaps->end();
790 ++lIter)
791 {
792 names.push_back(lIter.getKey());
793 }
794}
795
796
797/*******************************************************************************
798
799********************************************************************************/
731store::Iterator_t dynamic_context::listActiveICNames()800store::Iterator_t dynamic_context::listActiveICNames()
732{801{
733 return GENV_STORE.listActiveICNames();802 return GENV_STORE.listActiveICNames();
734803
=== modified file 'src/context/dynamic_context.h'
--- src/context/dynamic_context.h 2012-06-18 10:06:47 +0000
+++ src/context/dynamic_context.h 2012-06-23 00:29:20 +0000
@@ -123,6 +123,8 @@
123123
124 IndexMap * theAvailableIndices;124 IndexMap * theAvailableIndices;
125125
126 IndexMap * theAvailableMaps;
127
126 //MODIFY128 //MODIFY
127 EnvVarMap * theEnvironmentVariables;129 EnvVarMap * theEnvironmentVariables;
128130
@@ -204,6 +206,14 @@
204206
205 void unbindIndex(store::Item* qname);207 void unbindIndex(store::Item* qname);
206208
209 store::Index* getMap(store::Item* qname) const;
210
211 void bindMap(store::Item* qname, store::Index_t& index);
212
213 void unbindMap(store::Item* qname);
214
215 void getMapNames(std::vector<store::Item_t>& names) const;
216
207 /**217 /**
208 * Lists all active integrity constraints.218 * Lists all active integrity constraints.
209 */219 */
210220
=== modified file 'src/functions/pregenerated/func_maps.cpp'
--- src/functions/pregenerated/func_maps.cpp 2012-06-18 10:06:47 +0000
+++ src/functions/pregenerated/func_maps.cpp 2012-06-23 00:29:20 +0000
@@ -41,6 +41,16 @@
41 return new MapCreateIterator(sctx, loc, argv);41 return new MapCreateIterator(sctx, loc, argv);
42}42}
4343
44PlanIter_t zorba_store_data_structure_unordered_map_create_transient::codegen(
45 CompilerCB*,
46 static_context* sctx,
47 const QueryLoc& loc,
48 std::vector<PlanIter_t>& argv,
49 expr& ann) const
50{
51 return new MapCreateTransientIterator(sctx, loc, argv);
52}
53
44PlanIter_t zorba_store_data_structure_unordered_map_delete::codegen(54PlanIter_t zorba_store_data_structure_unordered_map_delete::codegen(
45 CompilerCB*,55 CompilerCB*,
46 static_context* sctx,56 static_context* sctx,
@@ -111,6 +121,16 @@
111 return new AvailableMapsIterator(sctx, loc, argv);121 return new AvailableMapsIterator(sctx, loc, argv);
112}122}
113123
124PlanIter_t zorba_store_data_structure_unordered_map_is_transient::codegen(
125 CompilerCB*,
126 static_context* sctx,
127 const QueryLoc& loc,
128 std::vector<PlanIter_t>& argv,
129 expr& ann) const
130{
131 return new MapIsTransientIterator(sctx, loc, argv);
132}
133
114void populate_context_maps(static_context* sctx)134void populate_context_maps(static_context* sctx)
115{135{
116136
@@ -129,6 +149,19 @@
129149
130150
131 {151 {
152 std::vector<xqtref_t> lParamTypes;
153 lParamTypes.push_back(GENV_TYPESYSTEM.QNAME_TYPE_ONE);
154 lParamTypes.push_back(GENV_TYPESYSTEM.QNAME_TYPE_ONE);DECL_WITH_KIND(sctx, zorba_store_data_structure_unordered_map_create_transient,
155 (createQName("http://www.zorba-xquery.com/modules/store/data-structures/unordered-map","","create-transient"),
156 lParamTypes, GENV_TYPESYSTEM.EMPTY_TYPE, true),
157 FunctionConsts::ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_CREATE_TRANSIENT_N);
158
159 }
160
161
162
163
164 {
132 DECL_WITH_KIND(sctx, zorba_store_data_structure_unordered_map_delete,165 DECL_WITH_KIND(sctx, zorba_store_data_structure_unordered_map_delete,
133 (createQName("http://www.zorba-xquery.com/modules/store/data-structures/unordered-map","","delete"), 166 (createQName("http://www.zorba-xquery.com/modules/store/data-structures/unordered-map","","delete"),
134 GENV_TYPESYSTEM.QNAME_TYPE_ONE, 167 GENV_TYPESYSTEM.QNAME_TYPE_ONE,
@@ -212,6 +245,18 @@
212245
213 }246 }
214247
248
249
250
251 {
252 DECL_WITH_KIND(sctx, zorba_store_data_structure_unordered_map_is_transient,
253 (createQName("http://www.zorba-xquery.com/modules/store/data-structures/unordered-map","","is-transient"),
254 GENV_TYPESYSTEM.QNAME_TYPE_ONE,
255 GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE),
256 FunctionConsts::ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_IS_TRANSIENT_1);
257
258 }
259
215}260}
216261
217262
218263
=== modified file 'src/functions/pregenerated/func_maps.h'
--- src/functions/pregenerated/func_maps.h 2012-06-18 10:06:47 +0000
+++ src/functions/pregenerated/func_maps.h 2012-06-23 00:29:20 +0000
@@ -57,6 +57,25 @@
57};57};
5858
5959
60//zorba-store-data-structure-unordered-map:create-transient
61class zorba_store_data_structure_unordered_map_create_transient : public function
62{
63public:
64 zorba_store_data_structure_unordered_map_create_transient(const signature& sig, FunctionConsts::FunctionKind kind)
65 :
66 function(sig, kind)
67 {
68
69 }
70
71 unsigned short getScriptingKind() const { return SEQUENTIAL_FUNC_EXPR; }
72
73 bool accessesDynCtx() const { return true; }
74
75 CODEGEN_DECL();
76};
77
78
60//zorba-store-data-structure-unordered-map:delete79//zorba-store-data-structure-unordered-map:delete
61class zorba_store_data_structure_unordered_map_delete : public function80class zorba_store_data_structure_unordered_map_delete : public function
62{81{
@@ -182,6 +201,23 @@
182};201};
183202
184203
204//zorba-store-data-structure-unordered-map:is-transient
205class zorba_store_data_structure_unordered_map_is_transient : public function
206{
207public:
208 zorba_store_data_structure_unordered_map_is_transient(const signature& sig, FunctionConsts::FunctionKind kind)
209 :
210 function(sig, kind)
211 {
212
213 }
214
215 bool accessesDynCtx() const { return true; }
216
217 CODEGEN_DECL();
218};
219
220
185} //namespace zorba221} //namespace zorba
186222
187223
188224
=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h 2012-06-18 10:06:47 +0000
+++ src/functions/pregenerated/function_enum.h 2012-06-23 00:29:20 +0000
@@ -401,6 +401,7 @@
401 ZORBA_STORE_DOCUMENTS_AVAILABLE_DOCUMENTS_0,401 ZORBA_STORE_DOCUMENTS_AVAILABLE_DOCUMENTS_0,
402 ZORBA_STORE_DOCUMENTS_IS_AVAILABLE_DOCUMENT_1,402 ZORBA_STORE_DOCUMENTS_IS_AVAILABLE_DOCUMENT_1,
403 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_CREATE_N,403 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_CREATE_N,
404 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_CREATE_TRANSIENT_N,
404 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_DELETE_1,405 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_DELETE_1,
405 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_GET_N,406 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_GET_N,
406 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_INSERT_N,407 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_INSERT_N,
@@ -408,6 +409,7 @@
408 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_KEYS_1,409 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_KEYS_1,
409 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_SIZE_1,410 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_SIZE_1,
410 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_AVAILABLE_MAPS_0,411 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_AVAILABLE_MAPS_0,
412 ZORBA_STORE_DATA_STRUCTURE_UNORDERED_MAP_IS_TRANSIENT_1,
411 FN_CODEPOINTS_TO_STRING_1,413 FN_CODEPOINTS_TO_STRING_1,
412 FN_STRING_TO_CODEPOINTS_1,414 FN_STRING_TO_CODEPOINTS_1,
413 FN_COMPARE_2,415 FN_COMPARE_2,
414416
=== modified file 'src/runtime/pregenerated/iterator_enum.h'
--- src/runtime/pregenerated/iterator_enum.h 2012-06-18 10:06:47 +0000
+++ src/runtime/pregenerated/iterator_enum.h 2012-06-23 00:29:20 +0000
@@ -300,6 +300,7 @@
300 TYPE_AvailableDocumentsIterator,300 TYPE_AvailableDocumentsIterator,
301 TYPE_IsAvailableDocumentIterator,301 TYPE_IsAvailableDocumentIterator,
302 TYPE_MapCreateIterator,302 TYPE_MapCreateIterator,
303 TYPE_MapCreateTransientIterator,
303 TYPE_MapDestroyIterator,304 TYPE_MapDestroyIterator,
304 TYPE_MapGetIterator,305 TYPE_MapGetIterator,
305 TYPE_MapInsertIterator,306 TYPE_MapInsertIterator,
@@ -307,6 +308,7 @@
307 TYPE_MapKeysIterator,308 TYPE_MapKeysIterator,
308 TYPE_MapSizeIterator,309 TYPE_MapSizeIterator,
309 TYPE_AvailableMapsIterator,310 TYPE_AvailableMapsIterator,
311 TYPE_MapIsTransientIterator,
310 TYPE_CodepointsToStringIterator,312 TYPE_CodepointsToStringIterator,
311 TYPE_StringToCodepointsIterator,313 TYPE_StringToCodepointsIterator,
312 TYPE_CompareStrIterator,314 TYPE_CompareStrIterator,
313315
=== modified file 'src/runtime/spec/store/maps.xml'
--- src/runtime/spec/store/maps.xml 2012-06-18 10:06:47 +0000
+++ src/runtime/spec/store/maps.xml 2012-06-23 00:29:20 +0000
@@ -12,12 +12,13 @@
12 xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">12 xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
13 13
14<zorba:source>14<zorba:source>
15 <zorba:include form="Quoted">store/api/iterator.h</zorba:include>15 <zorba:include form="Quoted">store/api/iterator.h</zorba:include>
16 <zorba:include form="Quoted">store/api/index.h</zorba:include>16 <zorba:include form="Quoted">store/api/index.h</zorba:include>
17</zorba:source>17</zorba:source>
1818
19<zorba:header>19<zorba:header>
20 <zorba:include form="Quoted">store/api/index.h</zorba:include>20 <zorba:include form="Quoted">store/api/index.h</zorba:include>
21 <zorba:include form="Angle-bracket">vector</zorba:include>
21</zorba:header>22</zorba:header>
22 23
2324
@@ -54,6 +55,35 @@
54/*******************************************************************************55/*******************************************************************************
55********************************************************************************/56********************************************************************************/
56-->57-->
58<zorba:iterator name="MapCreateTransientIterator" >
59
60 <zorba:description author="Matthias Brantner">
61 </zorba:description>
62
63 <zorba:function>
64
65 <zorba:signature
66 variadic="true"
67 localname="create-transient"
68 prefix="zorba-store-data-structure-unordered-map">
69 <zorba:param>xs:QName</zorba:param> <!-- name of the hashmap -->
70 <zorba:param>xs:QName</zorba:param> <!-- list of key types -->
71 <zorba:output>empty-sequence()</zorba:output>
72 </zorba:signature>
73
74 <zorba:methods>
75 <zorba:getScriptingKind returnValue="SEQUENTIAL_FUNC_EXPR"/>
76 <zorba:accessesDynCtx returnValue="true"/>
77 </zorba:methods>
78
79 </zorba:function>
80
81</zorba:iterator>
82
83<!--
84/*******************************************************************************
85********************************************************************************/
86-->
57<zorba:iterator name="MapDestroyIterator" >87<zorba:iterator name="MapDestroyIterator" >
5888
59 <zorba:description author="Matthias Brantner">89 <zorba:description author="Matthias Brantner">
@@ -238,10 +268,40 @@
238 </zorba:function>268 </zorba:function>
239269
240 <zorba:state generateInit="false" generateReset="false" generateDestructor="false">270 <zorba:state generateInit="false" generateReset="false" generateDestructor="false">
241 <zorba:member type="store::Iterator_t" name="nameItState"271 <zorba:member type="store::Iterator_t"
242 brief="the current iterator"/>272 name="persistentMapNamesIter"
273 brief="the current iterator"/>
274 <zorba:member type="std::vector&lt;store::Item_t>"
275 name="transientMapNames" brief="all the transient map names"/>
276 <zorba:member type="std::vector&lt;store::Item_t>::const_iterator"
277 name="transientMapNamesIter"
278 brief="the current iterator"/>
243 </zorba:state>279 </zorba:state>
244280
245</zorba:iterator>281</zorba:iterator>
246282
283<!--
284/*******************************************************************************
285********************************************************************************/
286-->
287<zorba:iterator name="MapIsTransientIterator" >
288
289 <zorba:description author="Matthias Brantner">
290 </zorba:description>
291
292 <zorba:function>
293
294 <zorba:signature localname="is-transient" prefix="zorba-store-data-structure-unordered-map">
295 <zorba:param>xs:QName</zorba:param>
296 <zorba:output>xs:boolean</zorba:output>
297 </zorba:signature>
298
299 <zorba:methods>
300 <zorba:accessesDynCtx returnValue="true"/>
301 </zorba:methods>
302
303 </zorba:function>
304
305</zorba:iterator>
306
247</zorba:iterators>307</zorba:iterators>
248308
=== modified file 'src/runtime/store/maps_impl.cpp'
--- src/runtime/store/maps_impl.cpp 2012-06-18 10:06:47 +0000
+++ src/runtime/store/maps_impl.cpp 2012-06-23 00:29:20 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright 2006-2008 The FLWOR Foundation.2 * Copyright 2006-2012 The FLWOR Foundation.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.5 * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "diagnostics/assert.h"18#include "diagnostics/assert.h"
19#include "diagnostics/util_macros.h"
19#include "diagnostics/xquery_diagnostics.h"20#include "diagnostics/xquery_diagnostics.h"
2021
21#include "zorbatypes/URI.h"22#include "zorbatypes/URI.h"
@@ -25,6 +26,7 @@
25#include "runtime/store/maps.h"26#include "runtime/store/maps.h"
2627
27#include "context/static_context.h"28#include "context/static_context.h"
29#include "context/dynamic_context.h"
28#include "context/namespace_context.h"30#include "context/namespace_context.h"
2931
30#include "store/api/pul.h"32#include "store/api/pul.h"
@@ -44,12 +46,9 @@
4446
45namespace zorba {47namespace zorba {
4648
47#define RAISE_ERROR(errcode, loc, params) \49/*******************************************************************************
48 throw XQUERY_EXCEPTION(errcode, \50********************************************************************************/
49 params, \51void
50 ERROR_LOC(loc));
51
52static void
53castOrCheckIndexType(52castOrCheckIndexType(
54 store::Item_t& aKeyItem,53 store::Item_t& aKeyItem,
55 const store::Item_t& aKeyType,54 const store::Item_t& aKeyType,
@@ -101,50 +100,105 @@
101 }100 }
102 }101 }
103}102}
104 103
105104
106/*******************************************************************************105/*******************************************************************************
107********************************************************************************/106********************************************************************************/
108bool107void
109MapCreateIterator::nextImpl(108checkMapTypes(
110 store::Item_t& result,109 std::vector<store::Item_t>& aTypes,
111 PlanState& aPlanState) const110 const store::Item_t& aMapName,
111 const QueryLoc& aLoc)
112{112{
113 store::Item_t lQName;
114 std::vector<store::Item_t> lTypes;
115 std::vector<zstring> lCollations;
116 std::auto_ptr<store::PUL> lPul;
117 long lTimezone = 0;
118 xqtref_t lAnyAtomicType, lIndexKeyType;113 xqtref_t lAnyAtomicType, lIndexKeyType;
119 size_t i;114
120115 for (size_t i = 0; i < aTypes.size(); ++i)
121 PlanIteratorState* state;
122 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
123
124 consumeNext(lQName, theChildren[0].getp(), aPlanState);
125
126 lTypes.resize(theChildren.size() - 1);
127 lCollations.resize(theChildren.size() - 1);
128 for (i = 1; i < theChildren.size(); ++i)
129 {116 {
130 consumeNext(lTypes[i-1], theChildren[i].getp(), aPlanState);
131
132 lAnyAtomicType = GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_ONE;117 lAnyAtomicType = GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_ONE;
133 lIndexKeyType = GENV_TYPESYSTEM.create_named_type(118 lIndexKeyType = GENV_TYPESYSTEM.create_named_type(
134 lTypes[i-1].getp(), TypeConstants::QUANT_ONE, loc);119 aTypes[i].getp(), TypeConstants::QUANT_ONE, aLoc);
135120
136 if (lIndexKeyType != NULL &&121 if (lIndexKeyType != NULL &&
137 !TypeOps::is_subtype(&GENV_TYPESYSTEM,122 !TypeOps::is_subtype(&GENV_TYPESYSTEM,
138 *lIndexKeyType, *lAnyAtomicType))123 *lIndexKeyType, *lAnyAtomicType))
139 {124 {
140 RAISE_ERROR(err::XPTY0004, loc,125 RAISE_ERROR(err::XPTY0004, aLoc,
141 ERROR_PARAMS(ZED(SearchKeyTypeMismatch_234),126 ERROR_PARAMS(ZED(SearchKeyTypeMismatch_234),
142 *lAnyAtomicType,127 *lAnyAtomicType,
143 lQName->getStringValue(),128 aMapName->getStringValue(),
144 *lIndexKeyType)129 *lIndexKeyType)
145 );130 );
146 }131 }
147 }132 }
133}
134
135
136/*******************************************************************************
137********************************************************************************/
138bool
139getMap(
140 const store::Item_t& aName,
141 const QueryLoc& aLoc,
142 dynamic_context* aContext,
143 store::Index*& aIndex)
144{
145 aIndex = GENV_STORE.getMap(aName);
146
147 if (aIndex) return true;
148
149 aIndex = aContext->getMap(aName.getp());
150
151 if (!aIndex)
152 {
153 RAISE_ERROR(
154 zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
155 aLoc,
156 ERROR_PARAMS( aName->getStringValue() )
157 );
158 }
159
160 return false;
161}
162
163
164
165/*******************************************************************************
166********************************************************************************/
167bool
168MapCreateIterator::nextImpl(
169 store::Item_t& result,
170 PlanState& aPlanState) const
171{
172 store::Item_t lQName;
173 std::vector<store::Item_t> lTypes;
174 std::vector<zstring> lCollations;
175 std::auto_ptr<store::PUL> lPul;
176 long lTimezone = 0;
177
178 PlanIteratorState* state;
179 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
180
181 consumeNext(lQName, theChildren[0].getp(), aPlanState);
182
183 if (GENV_STORE.getMap(lQName)
184 || aPlanState.theLocalDynCtx->getMap(lQName.getp()))
185 {
186 RAISE_ERROR(
187 zerr::ZSTR0001_INDEX_ALREADY_EXISTS,
188 loc,
189 ERROR_PARAMS( lQName->getStringValue() )
190 );
191 }
192
193 lCollations.resize(theChildren.size() - 1);
194 lTypes.resize(theChildren.size() - 1);
195
196 for (size_t i = 1; i < theChildren.size(); ++i)
197 {
198 consumeNext(lTypes[i-1], theChildren[i].getp(), aPlanState);
199 }
200
201 checkMapTypes(lTypes, lQName, loc);
148202
149 lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());203 lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
150 lPul->addCreateHashMap(&loc, lQName, lTypes, lCollations, lTimezone);204 lPul->addCreateHashMap(&loc, lQName, lTypes, lCollations, lTimezone);
@@ -165,40 +219,86 @@
165/*******************************************************************************219/*******************************************************************************
166********************************************************************************/220********************************************************************************/
167bool221bool
222MapCreateTransientIterator::nextImpl(
223 store::Item_t& result,
224 PlanState& aPlanState) const
225{
226 store::Item_t lQName;
227 store::IndexSpecification lSpec;
228 store::Index_t lIndex;
229 std::vector<std::string> lCollations;
230
231 PlanIteratorState* state;
232 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
233
234 consumeNext(lQName, theChildren[0].getp(), aPlanState);
235
236 if (GENV_STORE.getMap(lQName)
237 || aPlanState.theLocalDynCtx->getMap(lQName.getp()))
238 {
239 RAISE_ERROR(
240 zerr::ZSTR0001_INDEX_ALREADY_EXISTS,
241 loc,
242 ERROR_PARAMS( lQName->getStringValue() )
243 );
244 }
245
246 lCollations.resize(theChildren.size() - 1);
247 lSpec.theKeyTypes.resize(theChildren.size() - 1);
248
249 for (size_t i = 1; i < theChildren.size(); ++i)
250 {
251 consumeNext(lSpec.theKeyTypes[i-1], theChildren[i].getp(), aPlanState);
252 }
253
254 checkMapTypes(lSpec.theKeyTypes, lQName, loc);
255
256 lSpec.theNumKeyColumns = lSpec.theKeyTypes.size();
257 lSpec.theIsTemp = true;
258 lSpec.theCollations = lCollations;
259 lSpec.theTimezone = 0;
260
261 lIndex = GENV_STORE.createMap(lQName, lSpec);
262
263 aPlanState.theLocalDynCtx->bindMap(lIndex->getName(), lIndex);
264
265 result = NULL;
266
267 STACK_END(state);
268}
269
270
271/*******************************************************************************
272********************************************************************************/
273bool
168MapDestroyIterator::nextImpl(274MapDestroyIterator::nextImpl(
169 store::Item_t& result,275 store::Item_t& result,
170 PlanState& aPlanState) const276 PlanState& aPlanState) const
171{277{
172 store::Item_t lQName;278 store::Item_t lQName;
173 std::auto_ptr<store::PUL> lPul;279 store::Index* lIndex;
174 store::Index_t lIndex;
175280
176 PlanIteratorState* state;281 PlanIteratorState* state;
177 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);282 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
178283
179 consumeNext(lQName, theChildren[0].getp(), aPlanState);284 consumeNext(lQName, theChildren[0].getp(), aPlanState);
180285
181 lIndex = GENV_STORE.getMap(lQName);286 if (getMap(lQName, loc, aPlanState.theLocalDynCtx, lIndex))
182287 {
183 if (!lIndex)288 std::auto_ptr<store::PUL> lPul(GENV_ITEMFACTORY->createPendingUpdateList());
184 {289 lPul->addDestroyHashMap(&loc, lQName);
185 throw XQUERY_EXCEPTION(290
186 zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,291 apply_updates(
187 ERROR_PARAMS( lQName->getStringValue() ),292 aPlanState.theCompilerCB,
188 ERROR_LOC( loc )293 aPlanState.theGlobalDynCtx,
189 );294 theSctx,
190 }295 lPul.get(),
191296 loc);
192297 }
193 lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());298 else
194 lPul->addDestroyHashMap(&loc, lQName);299 {
195300 aPlanState.theLocalDynCtx->unbindMap(lQName.getp());
196 apply_updates(301 }
197 aPlanState.theCompilerCB,
198 aPlanState.theGlobalDynCtx,
199 theSctx,
200 lPul.get(),
201 loc);
202302
203 result = NULL;303 result = NULL;
204304
@@ -224,29 +324,20 @@
224324
225 consumeNext(lQName, theChildren[0].getp(), aPlanState);325 consumeNext(lQName, theChildren[0].getp(), aPlanState);
226326
227 lIndex = GENV_STORE.getMap(lQName);327 getMap(lQName, loc, aPlanState.theLocalDynCtx, lIndex);
228
229 if (!lIndex)
230 {
231 throw XQUERY_EXCEPTION(
232 zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
233 ERROR_PARAMS( lQName->getStringValue() ),
234 ERROR_LOC( loc )
235 );
236 }
237328
238 lSpec = lIndex->getSpecification();329 lSpec = lIndex->getSpecification();
239330
240 if (lSpec.getNumColumns() != theChildren.size() - 1)331 if (lSpec.getNumColumns() != theChildren.size() - 1)
241 {332 {
242 throw XQUERY_EXCEPTION(333 RAISE_ERROR(
243 zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,334 zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,
335 loc,
244 ERROR_PARAMS(336 ERROR_PARAMS(
245 lQName->getStringValue(),337 lQName->getStringValue(),
246 "map",338 "map",
247 theChildren.size() - 1,339 theChildren.size() - 1,
248 lSpec.getNumColumns() ),340 lSpec.getNumColumns() )
249 ERROR_LOC( loc )
250 );341 );
251 }342 }
252343
@@ -293,63 +384,85 @@
293{384{
294 store::Item_t lQName;385 store::Item_t lQName;
295 std::vector<store::Item_t> lKey;386 std::vector<store::Item_t> lKey;
296 store::Iterator_t lValue;
297 std::auto_ptr<store::PUL> lPul;
298 store::IndexSpecification lSpec;387 store::IndexSpecification lSpec;
299 store::Index_t lIndex;388 store::Index* lIndex;
389 bool lPersistent;
300390
301 PlanIteratorState* state;391 PlanIteratorState* state;
302 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);392 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
303393
304 consumeNext(lQName, theChildren[0].getp(), aPlanState);394 consumeNext(lQName, theChildren[0].getp(), aPlanState);
305395
306 lIndex = GENV_STORE.getMap(lQName);396 lPersistent = getMap(lQName, loc, aPlanState.theLocalDynCtx, lIndex);
307
308 if (!lIndex)
309 {
310 throw XQUERY_EXCEPTION(
311 zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
312 ERROR_PARAMS( lQName->getStringValue() ),
313 ERROR_LOC( loc )
314 );
315 }
316397
317 lSpec = lIndex->getSpecification();398 lSpec = lIndex->getSpecification();
318399
319 if (lSpec.getNumColumns() != theChildren.size() - 2)400 if (lSpec.getNumColumns() != theChildren.size() - 2)
320 {401 {
321 throw XQUERY_EXCEPTION(402 RAISE_ERROR(
322 zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,403 zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,
404 loc,
323 ERROR_PARAMS(405 ERROR_PARAMS(
324 lQName->getStringValue(),406 lQName->getStringValue(),
325 "map",407 "map",
326 theChildren.size() - 2,408 theChildren.size() - 2,
327 lSpec.getNumColumns() ),409 lSpec.getNumColumns() )
328 ERROR_LOC( loc )
329 );410 );
330 }411 }
331412
332 lValue = new PlanIteratorWrapper(theChildren[1], aPlanState);
333
334 lKey.resize(theChildren.size() - 2);413 lKey.resize(theChildren.size() - 2);
335 for (size_t i = 2; i < theChildren.size(); ++i)414 for (size_t i = 2; i < theChildren.size(); ++i)
336 {415 {
337 if (consumeNext(lKey[i-2], theChildren[i].getp(), aPlanState))416 if (consumeNext(lKey[i-2], theChildren[i].getp(), aPlanState))
338 {417 {
339 namespace_context tmp_ctx(theSctx);418 namespace_context tmp_ctx(theSctx);
340 castOrCheckIndexType(lKey[i-2], lSpec.theKeyTypes[i-2], lQName, &tmp_ctx, loc);419 castOrCheckIndexType(
341 }420 lKey[i-2],
342 }421 lSpec.theKeyTypes[i-2],
343422 lQName,
344 lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());423 &tmp_ctx,
345 lPul->addInsertIntoHashMap(&loc, lQName, lKey, lValue);424 loc);
346425 }
347 apply_updates(426 }
348 aPlanState.theCompilerCB,427
349 aPlanState.theGlobalDynCtx,428 if (lPersistent)
350 theSctx,429 {
351 lPul.get(),430 std::auto_ptr<store::PUL> lPul;
352 loc);431 store::Iterator_t lValue
432 = new PlanIteratorWrapper(theChildren[1], aPlanState);
433
434 lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
435 lPul->addInsertIntoHashMap(&loc, lQName, lKey, lValue);
436
437 apply_updates(
438 aPlanState.theCompilerCB,
439 aPlanState.theGlobalDynCtx,
440 theSctx,
441 lPul.get(),
442 loc);
443 }
444 else
445 {
446 store::Item_t lValue;
447 while (consumeNext(lValue, theChildren[1], aPlanState))
448 {
449 std::auto_ptr<store::IndexKey> k(new store::IndexKey());
450 for (std::vector<store::Item_t>::const_iterator lIter = lKey.begin();
451 lIter != lKey.end();
452 ++lIter)
453 {
454 k->push_back(*lIter);
455 }
456
457 store::IndexKey* lKeyPtr = k.get();
458 if (!lIndex->insert(lKeyPtr, lValue))
459 {
460 // the index took the ownership over the key if the index
461 // did _not_ already contain an entry with the same key
462 k.release();
463 }
464 }
465 }
353466
354 result = NULL;467 result = NULL;
355468
@@ -371,36 +484,28 @@
371 store::Item_t lKeyItem;484 store::Item_t lKeyItem;
372 std::auto_ptr<store::PUL> lPul;485 std::auto_ptr<store::PUL> lPul;
373 store::IndexSpecification lSpec;486 store::IndexSpecification lSpec;
487 bool lPersistent;
374488
375 PlanIteratorState* state;489 PlanIteratorState* state;
376 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);490 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
377491
378 consumeNext(lQName, theChildren[0].getp(), aPlanState);492 consumeNext(lQName, theChildren[0].getp(), aPlanState);
379493
380 lIndex = GENV_STORE.getMap(lQName);494 lPersistent = getMap(lQName, loc, aPlanState.theLocalDynCtx, lIndex);
381
382 if (!lIndex)
383 {
384 throw XQUERY_EXCEPTION(
385 zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
386 ERROR_PARAMS( lQName->getStringValue() ),
387 ERROR_LOC( loc )
388 );
389 }
390495
391 lSpec = lIndex->getSpecification();496 lSpec = lIndex->getSpecification();
392497
393 if (lSpec.getNumColumns() != theChildren.size() - 1)498 if (lSpec.getNumColumns() != theChildren.size() - 1)
394 {499 {
395 throw XQUERY_EXCEPTION(500 RAISE_ERROR(
396 zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,501 zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,
502 loc,
397 ERROR_PARAMS(503 ERROR_PARAMS(
398 lQName->getStringValue(),504 lQName->getStringValue(),
399 "map",505 "map",
400 theChildren.size() - 1,506 theChildren.size() - 1,
401 lSpec.getNumColumns()507 lSpec.getNumColumns()
402 ),508 )
403 ERROR_LOC( loc )
404 );509 );
405 }510 }
406511
@@ -414,15 +519,30 @@
414 }519 }
415 }520 }
416521
417 lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());522 if (lPersistent)
418 lPul->addRemoveFromHashMap(&loc, lQName, lKey);523 {
524 lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
525 lPul->addRemoveFromHashMap(&loc, lQName, lKey);
419526
420 apply_updates(527 apply_updates(
421 aPlanState.theCompilerCB,528 aPlanState.theCompilerCB,
422 aPlanState.theGlobalDynCtx,529 aPlanState.theGlobalDynCtx,
423 theSctx,530 theSctx,
424 lPul.get(),531 lPul.get(),
425 loc);532 loc);
533 }
534 else
535 {
536 store::IndexKey k;
537 for (std::vector<store::Item_t>::const_iterator lIter = lKey.begin();
538 lIter != lKey.end();
539 ++lIter)
540 {
541 k.push_back(*lIter);
542 }
543 store::Item_t lValue;
544 lIndex->remove(&k, lValue, true);
545 }
426546
427 result = NULL;547 result = NULL;
428548
@@ -454,16 +574,7 @@
454574
455 consumeNext(lQName, theChildren[0].getp(), aPlanState);575 consumeNext(lQName, theChildren[0].getp(), aPlanState);
456576
457 lIndex = GENV_STORE.getMap(lQName);577 getMap(lQName, loc, aPlanState.theLocalDynCtx, lIndex);
458
459 if (!lIndex)
460 {
461 throw XQUERY_EXCEPTION(
462 zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
463 ERROR_PARAMS( lQName->getStringValue() ),
464 ERROR_LOC( loc )
465 );
466 }
467578
468 state->theIter = lIndex->keys();579 state->theIter = lIndex->keys();
469580
@@ -494,18 +605,23 @@
494 static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,605 static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
495 "", "attribute");606 "", "attribute");
496607
497 GENV_ITEMFACTORY->createQName(lValueAttrName,
498 "", "", "value");
499
500 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;608 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
501609
502 GENV_ITEMFACTORY->createElementNode(610 GENV_ITEMFACTORY->createElementNode(
503 lAttrElem, result, lAttrNodeName, lTypeName,611 lAttrElem, result, lAttrNodeName, lTypeName,
504 true, false, theNSBindings, lBaseURI);612 true, false, theNSBindings, lBaseURI);
505613
506 lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;614 store::Item_t& lValue = (*lIter);
507 GENV_ITEMFACTORY->createAttributeNode(615 if (! lValue.isNull())
508 lValueAttr, lAttrElem.getp(), lValueAttrName, lTypeName, (*lIter));616 {
617 GENV_ITEMFACTORY->createQName(lValueAttrName,
618 "", "", "value");
619
620 lTypeName = lValue->getType();
621
622 GENV_ITEMFACTORY->createAttributeNode(
623 lValueAttr, lAttrElem.getp(), lValueAttrName, lTypeName, lValue);
624 }
509 }625 }
510 STACK_PUSH(true, state);626 STACK_PUSH(true, state);
511 }627 }
@@ -529,16 +645,7 @@
529645
530 consumeNext(lQName, theChildren[0].getp(), aPlanState);646 consumeNext(lQName, theChildren[0].getp(), aPlanState);
531647
532 lIndex = GENV_STORE.getMap(lQName);648 getMap(lQName, loc, aPlanState.theLocalDynCtx, lIndex);
533
534 if (!lIndex)
535 {
536 throw XQUERY_EXCEPTION(
537 zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
538 ERROR_PARAMS( lQName->getStringValue() ),
539 ERROR_LOC( loc )
540 );
541 }
542649
543 GENV_ITEMFACTORY->createInteger(result, xs_integer(lIndex->size()));650 GENV_ITEMFACTORY->createInteger(result, xs_integer(lIndex->size()));
544651
@@ -547,33 +654,36 @@
547 STACK_END(state);654 STACK_END(state);
548}655}
549656
657
550/*******************************************************************************658/*******************************************************************************
551659
552********************************************************************************/660********************************************************************************/
553AvailableMapsIteratorState::~AvailableMapsIteratorState()661AvailableMapsIteratorState::~AvailableMapsIteratorState()
554{662{
555 if ( nameItState != NULL ) 663 if ( persistentMapNamesIter != NULL )
556 {664 {
557 nameItState->close();665 persistentMapNamesIter->close();
558 nameItState = NULL;666 persistentMapNamesIter = NULL;
559 }667 }
668 transientMapNames.clear();
560}669}
561670
562671
563void AvailableMapsIteratorState::init(PlanState& planState)672void AvailableMapsIteratorState::init(PlanState& planState)
564{673{
565 PlanIteratorState::init(planState);674 PlanIteratorState::init(planState);
566 nameItState = NULL;675 persistentMapNamesIter = NULL;
567}676}
568677
569678
570void AvailableMapsIteratorState::reset(PlanState& planState)679void AvailableMapsIteratorState::reset(PlanState& planState)
571{680{
572 PlanIteratorState::reset(planState);681 PlanIteratorState::reset(planState);
573 if ( nameItState != NULL ) {682 if ( persistentMapNamesIter != NULL ) {
574 nameItState->close();683 persistentMapNamesIter->close();
575 nameItState = NULL;684 persistentMapNamesIter = NULL;
576 }685 }
686 transientMapNames.clear();
577}687}
578688
579689
@@ -585,18 +695,54 @@
585695
586 DEFAULT_STACK_INIT(AvailableMapsIteratorState, state, planState);696 DEFAULT_STACK_INIT(AvailableMapsIteratorState, state, planState);
587697
588 for ((state->nameItState = GENV_STORE.listMapNames())->open ();698 for ((state->persistentMapNamesIter = GENV_STORE.listMapNames())->open ();
589 state->nameItState->next(nameItem); ) 699 state->persistentMapNamesIter->next(nameItem); )
590 {700 {
591 result = nameItem;701 result = nameItem;
592 STACK_PUSH( true, state);702 STACK_PUSH( true, state);
593 }703 }
594704
595 state->nameItState->close();705 state->persistentMapNamesIter->close();
706
707 planState.theLocalDynCtx->getMapNames(state->transientMapNames);
708
709 for (state->transientMapNamesIter = state->transientMapNames.begin();
710 state->transientMapNamesIter != state->transientMapNames.end();
711 ++state->transientMapNamesIter)
712 {
713 result = *state->transientMapNamesIter;
714 STACK_PUSH( true, state);
715 }
596716
597 STACK_END (state);717 STACK_END (state);
598}718}
599719
600720
721/*******************************************************************************
722********************************************************************************/
723bool
724MapIsTransientIterator::nextImpl(
725 store::Item_t& result,
726 PlanState& aPlanState) const
727{
728 store::Item_t lQName;
729 store::Index* lIndex;
730 bool lPersistent;
731
732 PlanIteratorState* state;
733 DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
734
735 consumeNext(lQName, theChildren[0].getp(), aPlanState);
736
737 lPersistent = getMap(lQName, loc, aPlanState.theLocalDynCtx, lIndex);
738
739 GENV_ITEMFACTORY->createBoolean(result, !lPersistent);
740
741 STACK_PUSH(true, state);
742
743 STACK_END(state);
744}
745
746
601} // namespace zorba747} // namespace zorba
602/* vim:set et sw=2 ts=2: */748/* vim:set et sw=2 ts=2: */
603749
=== modified file 'src/runtime/store/pregenerated/maps.cpp'
--- src/runtime/store/pregenerated/maps.cpp 2012-06-18 10:06:47 +0000
+++ src/runtime/store/pregenerated/maps.cpp 2012-06-23 00:29:20 +0000
@@ -62,6 +62,34 @@
62// </MapCreateIterator>62// </MapCreateIterator>
6363
6464
65// <MapCreateTransientIterator>
66SERIALIZABLE_CLASS_VERSIONS(MapCreateTransientIterator)
67
68void MapCreateTransientIterator::serialize(::zorba::serialization::Archiver& ar)
69{
70 serialize_baseclass(ar,
71 (NaryBaseIterator<MapCreateTransientIterator, PlanIteratorState>*)this);
72}
73
74
75void MapCreateTransientIterator::accept(PlanIterVisitor& v) const
76{
77 v.beginVisit(*this);
78
79 std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
80 std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
81 for ( ; lIter != lEnd; ++lIter ){
82 (*lIter)->accept(v);
83 }
84
85 v.endVisit(*this);
86}
87
88MapCreateTransientIterator::~MapCreateTransientIterator() {}
89
90// </MapCreateTransientIterator>
91
92
65// <MapDestroyIterator>93// <MapDestroyIterator>
66SERIALIZABLE_CLASS_VERSIONS(MapDestroyIterator)94SERIALIZABLE_CLASS_VERSIONS(MapDestroyIterator)
6795
@@ -286,6 +314,34 @@
286// </AvailableMapsIterator>314// </AvailableMapsIterator>
287315
288316
317// <MapIsTransientIterator>
318SERIALIZABLE_CLASS_VERSIONS(MapIsTransientIterator)
319
320void MapIsTransientIterator::serialize(::zorba::serialization::Archiver& ar)
321{
322 serialize_baseclass(ar,
323 (NaryBaseIterator<MapIsTransientIterator, PlanIteratorState>*)this);
324}
325
326
327void MapIsTransientIterator::accept(PlanIterVisitor& v) const
328{
329 v.beginVisit(*this);
330
331 std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
332 std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
333 for ( ; lIter != lEnd; ++lIter ){
334 (*lIter)->accept(v);
335 }
336
337 v.endVisit(*this);
338}
339
340MapIsTransientIterator::~MapIsTransientIterator() {}
341
342// </MapIsTransientIterator>
343
344
289345
290}346}
291347
292348
=== modified file 'src/runtime/store/pregenerated/maps.h'
--- src/runtime/store/pregenerated/maps.h 2012-06-18 10:06:47 +0000
+++ src/runtime/store/pregenerated/maps.h 2012-06-23 00:29:20 +0000
@@ -29,6 +29,7 @@
2929
3030
31#include "runtime/base/narybase.h"31#include "runtime/base/narybase.h"
32#include <vector>
32#include "store/api/index.h"33#include "store/api/index.h"
3334
3435
@@ -70,6 +71,37 @@
70 * 71 *
71 * Author: Matthias Brantner72 * Author: Matthias Brantner
72 */73 */
74class MapCreateTransientIterator : public NaryBaseIterator<MapCreateTransientIterator, PlanIteratorState>
75{
76public:
77 SERIALIZABLE_CLASS(MapCreateTransientIterator);
78
79 SERIALIZABLE_CLASS_CONSTRUCTOR2T(MapCreateTransientIterator,
80 NaryBaseIterator<MapCreateTransientIterator, PlanIteratorState>);
81
82 void serialize( ::zorba::serialization::Archiver& ar);
83
84 MapCreateTransientIterator(
85 static_context* sctx,
86 const QueryLoc& loc,
87 std::vector<PlanIter_t>& children)
88 :
89 NaryBaseIterator<MapCreateTransientIterator, PlanIteratorState>(sctx, loc, children)
90 {}
91
92 virtual ~MapCreateTransientIterator();
93
94 void accept(PlanIterVisitor& v) const;
95
96 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
97};
98
99
100/**
101 *
102 *
103 * Author: Matthias Brantner
104 */
73class MapDestroyIterator : public NaryBaseIterator<MapDestroyIterator, PlanIteratorState>105class MapDestroyIterator : public NaryBaseIterator<MapDestroyIterator, PlanIteratorState>
74{ 106{
75public:107public:
@@ -289,7 +321,9 @@
289class AvailableMapsIteratorState : public PlanIteratorState321class AvailableMapsIteratorState : public PlanIteratorState
290{322{
291public:323public:
292 store::Iterator_t nameItState; //the current iterator324 store::Iterator_t persistentMapNamesIter; //the current iterator
325 std::vector<store::Item_t> transientMapNames; //all the transient map names
326 std::vector<store::Item_t>::const_iterator transientMapNamesIter; //the current iterator
293327
294 AvailableMapsIteratorState();328 AvailableMapsIteratorState();
295329
@@ -325,6 +359,37 @@
325};359};
326360
327361
362/**
363 *
364 *
365 * Author: Matthias Brantner
366 */
367class MapIsTransientIterator : public NaryBaseIterator<MapIsTransientIterator, PlanIteratorState>
368{
369public:
370 SERIALIZABLE_CLASS(MapIsTransientIterator);
371
372 SERIALIZABLE_CLASS_CONSTRUCTOR2T(MapIsTransientIterator,
373 NaryBaseIterator<MapIsTransientIterator, PlanIteratorState>);
374
375 void serialize( ::zorba::serialization::Archiver& ar);
376
377 MapIsTransientIterator(
378 static_context* sctx,
379 const QueryLoc& loc,
380 std::vector<PlanIter_t>& children)
381 :
382 NaryBaseIterator<MapIsTransientIterator, PlanIteratorState>(sctx, loc, children)
383 {}
384
385 virtual ~MapIsTransientIterator();
386
387 void accept(PlanIterVisitor& v) const;
388
389 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
390};
391
392
328}393}
329#endif394#endif
330/*395/*
331396
=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
--- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-06-18 10:06:47 +0000
+++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-06-23 00:29:20 +0000
@@ -621,6 +621,8 @@
621621
622 class MapCreateIterator;622 class MapCreateIterator;
623623
624 class MapCreateTransientIterator;
625
624 class MapDestroyIterator;626 class MapDestroyIterator;
625627
626 class MapGetIterator;628 class MapGetIterator;
@@ -635,6 +637,8 @@
635637
636 class AvailableMapsIterator;638 class AvailableMapsIterator;
637639
640 class MapIsTransientIterator;
641
638 class CodepointsToStringIterator;642 class CodepointsToStringIterator;
639643
640 class StringToCodepointsIterator;644 class StringToCodepointsIterator;
@@ -1580,6 +1584,9 @@
1580 virtual void beginVisit ( const MapCreateIterator& ) = 0;1584 virtual void beginVisit ( const MapCreateIterator& ) = 0;
1581 virtual void endVisit ( const MapCreateIterator& ) = 0;1585 virtual void endVisit ( const MapCreateIterator& ) = 0;
15821586
1587 virtual void beginVisit ( const MapCreateTransientIterator& ) = 0;
1588 virtual void endVisit ( const MapCreateTransientIterator& ) = 0;
1589
1583 virtual void beginVisit ( const MapDestroyIterator& ) = 0;1590 virtual void beginVisit ( const MapDestroyIterator& ) = 0;
1584 virtual void endVisit ( const MapDestroyIterator& ) = 0;1591 virtual void endVisit ( const MapDestroyIterator& ) = 0;
15851592
@@ -1601,6 +1608,9 @@
1601 virtual void beginVisit ( const AvailableMapsIterator& ) = 0;1608 virtual void beginVisit ( const AvailableMapsIterator& ) = 0;
1602 virtual void endVisit ( const AvailableMapsIterator& ) = 0;1609 virtual void endVisit ( const AvailableMapsIterator& ) = 0;
16031610
1611 virtual void beginVisit ( const MapIsTransientIterator& ) = 0;
1612 virtual void endVisit ( const MapIsTransientIterator& ) = 0;
1613
1604 virtual void beginVisit ( const CodepointsToStringIterator& ) = 0;1614 virtual void beginVisit ( const CodepointsToStringIterator& ) = 0;
1605 virtual void endVisit ( const CodepointsToStringIterator& ) = 0;1615 virtual void endVisit ( const CodepointsToStringIterator& ) = 0;
16061616
16071617
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
--- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-06-18 10:06:47 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-06-23 00:29:20 +0000
@@ -4064,6 +4064,20 @@
4064// </MapCreateIterator>4064// </MapCreateIterator>
40654065
40664066
4067// <MapCreateTransientIterator>
4068void PrinterVisitor::beginVisit ( const MapCreateTransientIterator& a) {
4069 thePrinter.startBeginVisit("MapCreateTransientIterator", ++theId);
4070 printCommons( &a, theId );
4071 thePrinter.endBeginVisit( theId );
4072}
4073
4074void PrinterVisitor::endVisit ( const MapCreateTransientIterator& ) {
4075 thePrinter.startEndVisit();
4076 thePrinter.endEndVisit();
4077}
4078// </MapCreateTransientIterator>
4079
4080
4067// <MapDestroyIterator>4081// <MapDestroyIterator>
4068void PrinterVisitor::beginVisit ( const MapDestroyIterator& a) {4082void PrinterVisitor::beginVisit ( const MapDestroyIterator& a) {
4069 thePrinter.startBeginVisit("MapDestroyIterator", ++theId);4083 thePrinter.startBeginVisit("MapDestroyIterator", ++theId);
@@ -4162,6 +4176,20 @@
4162// </AvailableMapsIterator>4176// </AvailableMapsIterator>
41634177
41644178
4179// <MapIsTransientIterator>
4180void PrinterVisitor::beginVisit ( const MapIsTransientIterator& a) {
4181 thePrinter.startBeginVisit("MapIsTransientIterator", ++theId);
4182 printCommons( &a, theId );
4183 thePrinter.endBeginVisit( theId );
4184}
4185
4186void PrinterVisitor::endVisit ( const MapIsTransientIterator& ) {
4187 thePrinter.startEndVisit();
4188 thePrinter.endEndVisit();
4189}
4190// </MapIsTransientIterator>
4191
4192
4165// <CodepointsToStringIterator>4193// <CodepointsToStringIterator>
4166void PrinterVisitor::beginVisit ( const CodepointsToStringIterator& a) {4194void PrinterVisitor::beginVisit ( const CodepointsToStringIterator& a) {
4167 thePrinter.startBeginVisit("CodepointsToStringIterator", ++theId);4195 thePrinter.startBeginVisit("CodepointsToStringIterator", ++theId);
41684196
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
--- src/runtime/visitors/pregenerated/printer_visitor.h 2012-06-18 10:06:47 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-06-23 00:29:20 +0000
@@ -949,6 +949,9 @@
949 void beginVisit( const MapCreateIterator& );949 void beginVisit( const MapCreateIterator& );
950 void endVisit ( const MapCreateIterator& );950 void endVisit ( const MapCreateIterator& );
951951
952 void beginVisit( const MapCreateTransientIterator& );
953 void endVisit ( const MapCreateTransientIterator& );
954
952 void beginVisit( const MapDestroyIterator& );955 void beginVisit( const MapDestroyIterator& );
953 void endVisit ( const MapDestroyIterator& );956 void endVisit ( const MapDestroyIterator& );
954957
@@ -970,6 +973,9 @@
970 void beginVisit( const AvailableMapsIterator& );973 void beginVisit( const AvailableMapsIterator& );
971 void endVisit ( const AvailableMapsIterator& );974 void endVisit ( const AvailableMapsIterator& );
972975
976 void beginVisit( const MapIsTransientIterator& );
977 void endVisit ( const MapIsTransientIterator& );
978
973 void beginVisit( const CodepointsToStringIterator& );979 void beginVisit( const CodepointsToStringIterator& );
974 void endVisit ( const CodepointsToStringIterator& );980 void endVisit ( const CodepointsToStringIterator& );
975981
976982
=== modified file 'src/store/api/index.h'
--- src/store/api/index.h 2012-06-18 10:06:47 +0000
+++ src/store/api/index.h 2012-06-23 00:29:20 +0000
@@ -427,6 +427,11 @@
427 * a general index427 * a general index
428 */428 */
429 virtual bool insert(store::IndexKey*& key, store::Item_t& item) = 0;429 virtual bool insert(store::IndexKey*& key, store::Item_t& item) = 0;
430
431 virtual bool remove(
432 const store::IndexKey* key,
433 const store::Item_t& item,
434 bool all = false) = 0;
430};435};
431436
432437
433438
=== modified file 'src/store/api/store.h'
--- src/store/api/store.h 2012-06-18 10:06:47 +0000
+++ src/store/api/store.h 2012-06-23 00:29:20 +0000
@@ -320,6 +320,10 @@
320320
321 /* --------------------------- Map Management ------------------------------*/321 /* --------------------------- Map Management ------------------------------*/
322322
323 virtual Index_t createMap(
324 const Item_t& qname,
325 const IndexSpecification& spec) = 0;
326
323 virtual Index* getMap(const Item* aQName) const = 0;327 virtual Index* getMap(const Item* aQName) const = 0;
324328
325 virtual Iterator_t listMapNames() = 0;329 virtual Iterator_t listMapNames() = 0;
326330
=== modified file 'src/store/naive/pul_primitives.cpp'
--- src/store/naive/pul_primitives.cpp 2012-06-18 10:06:47 +0000
+++ src/store/naive/pul_primitives.cpp 2012-06-23 00:29:20 +0000
@@ -1734,7 +1734,7 @@
1734 lSpec.theTimezone = theTimezone;1734 lSpec.theTimezone = theTimezone;
17351735
17361736
1737 GET_STORE().createHashMap(theQName, lSpec);1737 GET_STORE().createMap(theQName, lSpec);
1738 theIsApplied = true;1738 theIsApplied = true;
1739}1739}
17401740
@@ -1743,7 +1743,7 @@
1743{1743{
1744 if (theIsApplied)1744 if (theIsApplied)
1745 {1745 {
1746 GET_STORE().destroyHashMap(theQName);1746 GET_STORE().destroyMap(theQName);
1747 }1747 }
1748}1748}
17491749
@@ -1763,7 +1763,7 @@
17631763
1764void UpdDestroyHashMap::apply()1764void UpdDestroyHashMap::apply()
1765{1765{
1766 theMap = GET_STORE().destroyHashMap(theQName);1766 theMap = GET_STORE().destroyMap(theQName);
1767 theIsApplied = true;1767 theIsApplied = true;
1768}1768}
17691769
@@ -1772,7 +1772,7 @@
1772{1772{
1773 if (theIsApplied)1773 if (theIsApplied)
1774 {1774 {
1775 GET_STORE().addHashMap(theMap);1775 GET_STORE().addMap(theMap);
1776 }1776 }
1777}1777}
17781778
@@ -1796,7 +1796,7 @@
17961796
1797void UpdInsertIntoHashMap::apply()1797void UpdInsertIntoHashMap::apply()
1798{1798{
1799 store::Index_t lMap = GET_STORE().getHashMap(theQName);1799 store::Index_t lMap = GET_STORE().getMap(theQName);
18001800
1801 if (!lMap)1801 if (!lMap)
1802 {1802 {
@@ -1809,7 +1809,6 @@
1809 theValue->open();1809 theValue->open();
1810 store::Item_t lValue;1810 store::Item_t lValue;
18111811
1812 store::IndexKey lKeyPtr;
1813 while (theValue->next(lValue))1812 while (theValue->next(lValue))
1814 {1813 {
1815 std::auto_ptr<store::IndexKey> lKey(new store::IndexKey());1814 std::auto_ptr<store::IndexKey> lKey(new store::IndexKey());
@@ -1853,7 +1852,7 @@
18531852
1854void UpdRemoveFromHashMap::apply()1853void UpdRemoveFromHashMap::apply()
1855{1854{
1856 store::Index_t lMap = GET_STORE().getHashMap(theQName);1855 store::Index_t lMap = GET_STORE().getMap(theQName);
18571856
1858 if (!lMap)1857 if (!lMap)
1859 {1858 {
18601859
=== modified file 'src/store/naive/simple_index_general.cpp'
--- src/store/naive/simple_index_general.cpp 2012-06-18 10:06:47 +0000
+++ src/store/naive/simple_index_general.cpp 2012-06-23 00:29:20 +0000
@@ -747,7 +747,7 @@
747*******************************************************************************/747*******************************************************************************/
748bool GeneralHashIndex::remove(748bool GeneralHashIndex::remove(
749 const store::Item_t& key,749 const store::Item_t& key,
750 store::Item_t& item,750 const store::Item_t& item,
751 bool all)751 bool all)
752{752{
753 assert(false);753 assert(false);
@@ -922,7 +922,7 @@
922*******************************************************************************/922*******************************************************************************/
923bool GeneralTreeIndex::remove(923bool GeneralTreeIndex::remove(
924 const store::Item_t& key,924 const store::Item_t& key,
925 store::Item_t& item,925 const store::Item_t& item,
926 bool all)926 bool all)
927{927{
928 return true;928 return true;
929929
=== modified file 'src/store/naive/simple_index_general.h'
--- src/store/naive/simple_index_general.h 2012-06-18 10:06:47 +0000
+++ src/store/naive/simple_index_general.h 2012-06-23 00:29:20 +0000
@@ -176,7 +176,12 @@
176176
177 bool insert(store::IndexKey*& key, store::Item_t& value);177 bool insert(store::IndexKey*& key, store::Item_t& value);
178178
179 virtual bool remove(const store::Item_t& key, store::Item_t& item, bool all) = 0;179 virtual bool remove(const store::Item_t& key, const store::Item_t& item, bool all) = 0;
180
181 virtual bool remove(
182 const store::IndexKey* key,
183 const store::Item_t& item,
184 bool all = false) = 0;
180};185};
181186
182187
@@ -237,7 +242,16 @@
237242
238 Index::KeyIterator_t keys() const;243 Index::KeyIterator_t keys() const;
239244
240 bool remove(const store::Item_t& key, store::Item_t& item, bool);245 bool remove(const store::Item_t& key, const store::Item_t& item, bool);
246
247 bool remove(
248 const store::IndexKey* key,
249 const store::Item_t& item,
250 bool all = false)
251 {
252 assert(key->size() == 1);
253 return remove(((*key)[0]), item, all);
254 }
241255
242 void clear();256 void clear();
243};257};
@@ -292,7 +306,16 @@
292306
293 Index::KeyIterator_t keys() const;307 Index::KeyIterator_t keys() const;
294308
295 bool remove(const store::Item_t& key, store::Item_t& item, bool all);309 bool remove(const store::Item_t& key, const store::Item_t& item, bool all);
310
311 bool remove(
312 const store::IndexKey* key,
313 const store::Item_t& item,
314 bool all = false)
315 {
316 assert(key->size() == 1);
317 return remove(((*key)[0]), item, all);
318 }
296319
297 void clear();320 void clear();
298};321};
299322
=== modified file 'src/store/naive/store.cpp'
--- src/store/naive/store.cpp 2012-06-22 08:19:01 +0000
+++ src/store/naive/store.cpp 2012-06-23 00:29:20 +0000
@@ -889,7 +889,7 @@
889889
890********************************************************************************/890********************************************************************************/
891store::Index_t891store::Index_t
892Store::createHashMap(892Store::createMap(
893 const store::Item_t& aQName,893 const store::Item_t& aQName,
894 const store::IndexSpecification& aSpec)894 const store::IndexSpecification& aSpec)
895{895{
@@ -905,7 +905,7 @@
905905
906 lIndex = new ValueHashIndex(aQName, aSpec);906 lIndex = new ValueHashIndex(aQName, aSpec);
907907
908 addHashMap(lIndex);908 if (!aSpec.theIsTemp) addMap(lIndex);
909909
910 return lIndex;910 return lIndex;
911}911}
@@ -915,7 +915,7 @@
915915
916********************************************************************************/916********************************************************************************/
917store::Index_t917store::Index_t
918Store::destroyHashMap(const store::Item_t& aQName)918Store::destroyMap(const store::Item_t& aQName)
919{919{
920 store::Index_t lIndex;920 store::Index_t lIndex;
921 if (!theHashMaps.get(aQName.getp(), lIndex))921 if (!theHashMaps.get(aQName.getp(), lIndex))
@@ -950,7 +950,7 @@
950950
951********************************************************************************/951********************************************************************************/
952store::Index_t952store::Index_t
953Store::getHashMap(const store::Item_t& aQName) const953Store::getMap(const store::Item_t& aQName) const
954{954{
955 store::Index_t lIndex;955 store::Index_t lIndex;
956 if (const_cast<IndexSet*>(&theHashMaps)->get(aQName.getp(), lIndex))956 if (const_cast<IndexSet*>(&theHashMaps)->get(aQName.getp(), lIndex))
@@ -968,7 +968,7 @@
968968
969********************************************************************************/969********************************************************************************/
970void970void
971Store::addHashMap(const store::Index_t& aIndex)971Store::addMap(const store::Index_t& aIndex)
972{972{
973 store::Item* lName = aIndex->getName();973 store::Item* lName = aIndex->getName();
974 store::Index_t lIndex = aIndex;974 store::Index_t lIndex = aIndex;
975975
=== modified file 'src/store/naive/store.h'
--- src/store/naive/store.h 2012-06-18 10:06:47 +0000
+++ src/store/naive/store.h 2012-06-23 00:29:20 +0000
@@ -342,17 +342,17 @@
342342
343/*------------------------------------- Maps ---------------------------------*/343/*------------------------------------- Maps ---------------------------------*/
344public:344public:
345 virtual store::Index_t createHashMap(345 virtual store::Index_t createMap(
346 const store::Item_t& aQName,346 const store::Item_t& aQName,
347 const store::IndexSpecification& aSpec);347 const store::IndexSpecification& aSpec);
348348
349 virtual store::Index_t destroyHashMap(const store::Item_t& aQName);349 virtual store::Index_t destroyMap(const store::Item_t& aQName);
350350
351 virtual store::Index* getMap(const store::Item* aQName) const;351 virtual store::Index* getMap(const store::Item* aQName) const;
352352
353 virtual store::Index_t getHashMap(const store::Item_t& aQName) const;353 virtual store::Index_t getMap(const store::Item_t& aQName) const;
354354
355 virtual void addHashMap(const store::Index_t& aMap);355 virtual void addMap(const store::Index_t& aMap);
356356
357 virtual store::Iterator_t listMapNames();357 virtual store::Iterator_t listMapNames();
358358
359359
=== added file 'test/rbkt/ExpQueryResults/zorba/store/unordered-map/map7.xml.res'
--- test/rbkt/ExpQueryResults/zorba/store/unordered-map/map7.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/store/unordered-map/map7.xml.res 2012-06-23 00:29:20 +0000
@@ -0,0 +1,1 @@
1true true 1 key1 value1 true false 3 true true 5 key5 value5 false true key2 false true key4 false false
02
=== added file 'test/rbkt/ExpQueryResults/zorba/store/unordered-map/transient-map0.xml.res'
--- test/rbkt/ExpQueryResults/zorba/store/unordered-map/transient-map0.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/store/unordered-map/transient-map0.xml.res 2012-06-23 00:29:20 +0000
@@ -0,0 +1,1 @@
1<avail>first</avail><contains>value5</contains><contains></contains><avail></avail>
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/store/unordered-map/map7.xq'
--- test/rbkt/Queries/zorba/store/unordered-map/map7.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/store/unordered-map/map7.xq 2012-06-23 00:29:20 +0000
@@ -0,0 +1,22 @@
1import module namespace map = "http://www.zorba-xquery.com/modules/store/data-structures/unordered-map";
2
3variable $name := fn:QName("http://www.zorba-xquery.com/map", "first");
4variable $xs-integer := fn:QName("http://www.w3.org/2001/XMLSchema", "xs:integer");
5variable $xs-string := fn:QName("http://www.w3.org/2001/XMLSchema", "xs:string");
6
7map:create($name, $xs-integer, $xs-string);
8
9for $i in 1 to 6
10let $value := concat("value", $i),
11 $key1 := if ($i mod 2 ne 0) then $i else (),
12 $key2 := if ($i mod 3 ne 0) then concat("key", $i) else ()
13return
14 map:insert($name, $value, $key1, $key2);
15
16for $k in map:keys($name)
17let $key1 := data($k/map:attribute[1]/@value),
18 $key2 := data($k/map:attribute[2]/@value)
19order by $key1, $key2
20return
21 ($key1 instance of xs:integer, $key2 instance of xs:string,
22 $key1, $key2, map:get($name, $key1, $key2))
023
=== added file 'test/rbkt/Queries/zorba/store/unordered-map/transient-map0.xq'
--- test/rbkt/Queries/zorba/store/unordered-map/transient-map0.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/store/unordered-map/transient-map0.xq 2012-06-23 00:29:20 +0000
@@ -0,0 +1,27 @@
1import module namespace map = "http://www.zorba-xquery.com/modules/store/data-structures/unordered-map";
2
3
4let $name := fn:QName("http://www.zorba-xquery.com/map", "first")
5let $type := fn:QName("http://www.w3.org/2001/XMLSchema", "xs:integer")
6return
7 {
8 map:create-transient($name, $type);
9
10 (
11 for $i in 1 to 1000
12 return map:insert($name, concat("value", $i), $i)
13 );
14
15 variable $res := <avail>{ map:available-maps() }</avail>;
16
17 $res := ($res, <contains>{ map:get($name, 5) }</contains>);
18
19 map:remove($name, 5);
20
21 $res := ($res, <contains>{ map:get($name, 5) }</contains>);
22
23 map:delete($name);
24
25 ($res, <avail>{ map:available-maps() }</avail>)
26 }
27

Subscribers

People subscribed via source and target branches