Sorin Marian Nasoi has proposed merging lp:~zorba-coders/zorba/my_queue into lp:zorba/queue-module.
Requested reviews: Zorba Coders (zorba-coders) Sorin Marian Nasoi (sorin.marian.nasoi) For more details, see: https://code.launchpad.net/~zorba-coders/zorba/my_queue/+merge/95133 - the names of the queues are now xs:QNames instead of xs:string - the module was moved inside 'src' folder - corrected some typos inside the module -- https://code.launchpad.net/~zorba-coders/zorba/my_queue/+merge/95133 Your team Zorba Coders is requested to review the proposed merge of lp:~zorba-coders/zorba/my_queue into lp:zorba/queue-module.
=== modified file 'CMakeLists.txt' --- CMakeLists.txt 2012-01-23 14:34:33 +0000 +++ CMakeLists.txt 2012-02-29 09:13:26 +0000 @@ -22,6 +22,6 @@ INCLUDE ("${Zorba_USE_FILE}") -ADD_SUBDIRECTORY("src/com/zorba-xquery/www/modules/store/data-structures") +ADD_SUBDIRECTORY("src") DONE_DECLARING_ZORBA_URIS() === added file 'src/CMakeLists.txt' --- src/CMakeLists.txt 1970-01-01 00:00:00 +0000 +++ src/CMakeLists.txt 2012-02-29 09:13:26 +0000 @@ -0,0 +1,20 @@ +# Copyright 2006-2008 The FLWOR Foundation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +##### Queue data structure + +DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/store/data-structures/queue" VERSION 1.0 FILE "queue.xq") + +ADD_TEST_DIRECTORY("${PROJECT_SOURCE_DIR}/test") === removed directory 'src/com' === removed directory 'src/com/zorba-xquery' === removed directory 'src/com/zorba-xquery/www' === removed directory 'src/com/zorba-xquery/www/modules' === removed directory 'src/com/zorba-xquery/www/modules/store' === removed directory 'src/com/zorba-xquery/www/modules/store/data-structures' === removed file 'src/com/zorba-xquery/www/modules/store/data-structures/CMakeLists.txt' --- src/com/zorba-xquery/www/modules/store/data-structures/CMakeLists.txt 2012-01-23 14:34:33 +0000 +++ src/com/zorba-xquery/www/modules/store/data-structures/CMakeLists.txt 1970-01-01 00:00:00 +0000 @@ -1,20 +0,0 @@ -# Copyright 2006-2008 The FLWOR Foundation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -##### Queue data structure - -DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/store/data-structures/queue" VERSION 1.0 FILE "queue.xq") - -ADD_TEST_DIRECTORY("${PROJECT_SOURCE_DIR}/test") === removed file 'src/com/zorba-xquery/www/modules/store/data-structures/queue.xq' --- src/com/zorba-xquery/www/modules/store/data-structures/queue.xq 2012-02-07 10:25:28 +0000 +++ src/com/zorba-xquery/www/modules/store/data-structures/queue.xq 1970-01-01 00:00:00 +0000 @@ -1,197 +0,0 @@ -xquery version "3.0"; - -(: - : Copyright 2006-2012 The FLWOR Foundation. - : - : Licensed under the Apache License, Version 2.0 (the "License"); - : you may not use this file except in compliance with the License. - : You may obtain a copy of the License at - : - : http://www.apache.org/licenses/LICENSE-2.0 - : - : Unless required by applicable law or agreed to in writing, software - : distributed under the License is distributed on an "AS IS" BASIS, - : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - : See the License for the specific language governing permissions and - : limitations under the License. -:) - -(:~ - : Implementation of queue for node items, using collections data structures.<br /> - : Queues are created at first node insert. - : - : @author Daniel Turcanu - : @project store/data structures - :) -module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; - -import module namespace collections-ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl"; -import module namespace collections-dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml"; - -declare namespace ann = "http://www.zorba-xquery.com/annotations"; -declare namespace ver = "http://www.zorba-xquery.com/options/versioning"; -declare option ver:module-version "1.0"; - -(:~ - : URI for all collections QNames. Queue names are combined with this URI to construct QNames used by collection api. - : The URI is "http://www.zorba-xquery.com/modules/store/data-structures/queue". - :) -declare variable $queue:global-uri := "http://www.zorba-xquery.com/modules/store/data-structures/queue"; - -(:~ - : Create a queue with this name. <br /> If queue exists, it is deleted first. - : @param $name string name of the new queue -:) -declare %ann:sequential function queue:create($name as xs:string) -{ - variable $qname := fn:QName($queue:global-uri, $name); - queue:delete($name); - collections-ddl:create($qname); -}; - -(:~ - : Return a list of string names for available queues. - : @return the list of created queue names - : @example test/Queries/available1.xq -:) -declare function queue:available-queues() as xs:string* -{ - for $coll-qname in collections-ddl:available-collections() - where fn:namespace-uri-from-QName($coll-qname) eq $queue:global-uri - return fn:local-name-from-QName($coll-qname) -}; - -(:~ - : Return the first node in the queue (the first added), without removing it. - : @param $name name of the queue - : @return the first node, or empty sequence if queue is empty - : @example test/Queries/front1.xq -:) -declare function queue:front($name as xs:string) as node()? -{ - let $qname := fn:QName($queue:global-uri, $name) - let $queue-content := collections-dml:collection($qname) - return - if(fn:not(fn:empty($queue-content))) then - $queue-content[1] - else - () -}; - -(:~ - : Return the last node in the queue (the last added), without removing it. - : @param $name string name of the queue - : @return the last node, or empty sequence if queue is empty - : @example test/Queries/back1.xq -:) -declare function queue:back($name as xs:string) as node()? -{ - let $qname := fn:QName($queue:global-uri, $name) - let $queue-content := collections-dml:collection($qname) - return - if(fn:not(fn:empty($queue-content))) then - $queue-content[fn:last()] - else - () -}; - -(:~ - : Return the first node in the queue, and remove it. - : @param $name string name of the queue - : @return the first node, or empty sequence if queue is empty - : @example test/Queries/pop2.xq -:) -declare %ann:sequential function queue:pop($name as xs:string) as node()? -{ - variable $qname := fn:QName($queue:global-uri, $name); - let $queue-content := collections-dml:collection($qname) - return - if(fn:not(fn:empty($queue-content))) then - { - variable $top-node := $queue-content[1]; - collections-dml:delete-node-first($qname); - $top-node - } - else - () -}; - -(:~ - : Add a new node to the queue. - : @param $name string name of the stack - : @param $value the node to be added - : @example test/Queries/push1.xq -:) -declare %ann:sequential function queue:push($name as xs:string, $value as node()) -{ - variable $qname := fn:QName($queue:global-uri, $name); - collections-dml:apply-insert-nodes-last($qname, $value); -}; - -(:~ - : Checks if a queue exists and is empty. - : @param $name string name of the queue - : @return true is the queue is empty or does not exist - : @example test/Queries/empty1.xq -:) -declare function queue:empty($name as xs:string) as xs:boolean -{ - let $qname := fn:QName($queue:global-uri, $name) - return - if(collections-ddl:is-available-collection($qname)) then - fn:empty(collections-dml:collection($qname)) - else - fn:true() -}; - -(:~ - : Get the count of nodes in the queue. - : @param $name string name of the queue - : @return the count of nodes - : @example test/Queries/size1.xq -:) -declare function queue:size($name as xs:string) as xs:integer -{ - let $qname := fn:QName($queue:global-uri, $name) - return - fn:count(collections-dml:collection($qname)) -}; - -(:~ - : Remove the queue with all the nodes in it. - : @param $name string name of the queue - : @example test/Queries/delete1.xq -:) -declare %ann:sequential function queue:delete($name as xs:string) -{ - variable $qname := fn:QName($queue:global-uri, $name); - if(collections-ddl:is-available-collection($qname)) then - { - variable $queue-size := queue:size($name); - collections-dml:delete-nodes-first($qname, $queue-size); - collections-ddl:delete($qname); - () - } - else - () -}; - -(:~ - : Copy all nodes from source queue to a destination queue.<br /> - : If destination queue does not exist, it is created first. <br /> - : If destination queue is not empty, the nodes are appended last. - : @param $destname string name of the destination queue - : @param $sourcename string name of the source queue - : @example test/Queries/copy1.xq -:) -declare %ann:sequential function queue:copy($destname as xs:string, $sourcename as xs:string) -{ - variable $destqname := fn:QName($queue:global-uri, $destname); - if(fn:not(collections-ddl:is-available-collection($destqname))) then - collections-ddl:create($destqname); - else - (); - variable $sourceqname := fn:QName($queue:global-uri, $sourcename); - collections-dml:insert-nodes-last($destqname, collections-dml:collection($sourceqname)); -}; - === added file 'src/queue.xq' --- src/queue.xq 1970-01-01 00:00:00 +0000 +++ src/queue.xq 2012-02-29 09:13:26 +0000 @@ -0,0 +1,178 @@ +xquery version "3.0"; + +(: + : Copyright 2006-2012 The FLWOR Foundation. + : + : Licensed under the Apache License, Version 2.0 (the "License"); + : you may not use this file except in compliance with the License. + : You may obtain a copy of the License at + : + : http://www.apache.org/licenses/LICENSE-2.0 + : + : Unless required by applicable law or agreed to in writing, software + : distributed under the License is distributed on an "AS IS" BASIS, + : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + : See the License for the specific language governing permissions and + : limitations under the License. +:) + +(:~ + : Implementation of queue for node items, using collections data structures.<br /> + : Queues are created at first node insert. + : + : @author Daniel Turcanu + : @project store/data structures + :) +module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; + +import module namespace collections-ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl"; +import module namespace collections-dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml"; + +declare namespace ann = "http://www.zorba-xquery.com/annotations"; +declare namespace ver = "http://www.zorba-xquery.com/options/versioning"; +declare option ver:module-version "1.0"; + +(:~ + : Create a queue with this name. <br /> If queue exists, it is deleted first. + : @param $name name of the new queue. +:) +declare %ann:sequential function queue:create( $name as xs:QName ) +{ + queue:delete($name); + collections-ddl:create($name); +}; + +(:~ + : Return a list of xs:QNames for available queues. + : @return the list of created queue names. + : @example test/Queries/available1.xq +:) +declare function queue:available-queues() as xs:QName* +{ + for $collQname in collections-ddl:available-collections() + return $collQname +}; + +(:~ + : Return the first node in the queue (the first added), without removing it. + : @param $name name of the queue. + : @return the first node, or empty sequence if queue is empty. + : @example test/Queries/front1.xq +:) +declare function queue:front($name as xs:QName) as node()? +{ + let $queueContent := collections-dml:collection($name) + return + if(fn:not(fn:empty($queueContent))) then + $queueContent[1] + else + () +}; + +(:~ + : Return the last node in the queue (the last added), without removing it. + : @param $name name of the queue. + : @return the last node, or empty sequence if queue is empty. + : @example test/Queries/back1.xq +:) +declare function queue:back($name as xs:QName) as node()? +{ + let $queueContent := collections-dml:collection($name) + return + if(fn:not(fn:empty($queueContent))) then + $queueContent[fn:last()] + else + () +}; + +(:~ + : Return the first node in the queue, and remove it. + : @param $name name of the queue. + : @return the first node, or empty sequence if queue is empty. + : @example test/Queries/pop2.xq +:) +declare %ann:sequential function queue:pop($name as xs:QName) as node()? +{ + let $queueContent := collections-dml:collection($name) + return + if(fn:not(fn:empty($queueContent))) then + { + variable $topNode := $queueContent[1]; + collections-dml:delete-node-first($name); + $topNode + } + else + () +}; + +(:~ + : Add a new node to the queue. + : @param $name name of the queue. + : @param $value the node to be added. + : @example test/Queries/push1.xq +:) +declare %ann:sequential function queue:push($name as xs:QName, $value as node()) +{ + collections-dml:apply-insert-nodes-last($name, $value); +}; + +(:~ + : Checks if a queue exists and is empty. + : @param $name name of the queue. + : @return true is the queue is empty or does not exist. + : @example test/Queries/empty1.xq +:) +declare function queue:empty($name as xs:QName) as xs:boolean +{ + if(collections-ddl:is-available-collection($name)) then + fn:empty(collections-dml:collection($name)) + else + fn:true() +}; + +(:~ + : Count of nodes in the queue. + : @param $name name of the queue. + : @return the count of nodes. + : @example test/Queries/size1.xq +:) +declare function queue:size($name as xs:QName) as xs:integer +{ + fn:count(collections-dml:collection($name)) +}; + +(:~ + : Remove the queue with all the nodes in it. + : @param $name name of the queue. + : @example test/Queries/delete1.xq +:) +declare %ann:sequential function queue:delete($name as xs:QName) +{ + if(collections-ddl:is-available-collection($name)) then + { + variable $queueSize := queue:size($name); + collections-dml:delete-nodes-first($name, $queueSize); + collections-ddl:delete($name); + () + } + else + () +}; + +(:~ + : Copy all nodes from source queue to a destination queue.<br /> + : If destination queue does not exist, it is created first. <br /> + : If destination queue is not empty, the nodes are appended last. + : @param $destName name of the destination queue. + : @param $sourceName name of the source queue. + : @example test/Queries/copy1.xq +:) +declare %ann:sequential function queue:copy($destName as xs:QName, $sourceName as xs:QName) +{ + if(fn:not(collections-ddl:is-available-collection($destName))) then + collections-ddl:create($destName); + else + (); + collections-dml:insert-nodes-last($destName, collections-dml:collection($sourceName)); +}; + === modified file 'test/Queries/available1.xq' --- test/Queries/available1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/available1.xq 2012-02-29 09:13:26 +0000 @@ -1,7 +1,8 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; import module namespace collections-ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl"; -collections-ddl:create(fn:QName("http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl", "queue12")); +variable $name := fn:QName("http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl", "queue1"); +collections-ddl:create($name); -queue:create("queue1"); +queue:create($name); queue:available-queues() === modified file 'test/Queries/back1.xq' --- test/Queries/back1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/back1.xq 2012-02-29 09:13:26 +0000 @@ -1,6 +1,7 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:create("queue1"); -queue:push("queue1", <a/>); -queue:push("queue1", <b/>); -queue:back("queue1") \ No newline at end of file +variable $name := fn:QName("", "queue1"); +queue:create($name); +queue:push($name, <a/>); +queue:push($name, <b/>); +queue:back($name) \ No newline at end of file === modified file 'test/Queries/copy1.xq' --- test/Queries/copy1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/copy1.xq 2012-02-29 09:13:26 +0000 @@ -1,9 +1,11 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:create("queue1"); -queue:push("queue1", <a/>); -queue:push("queue1", <b/>); -queue:copy("queue-copy", "queue1"); -queue:push("queue-copy", <c/>); -queue:push("queue-copy", <d/>); -(queue:front("queue-copy"), queue:size("queue-copy")) +variable $name := fn:QName("", "queue1"); +variable $nameCopy := fn:QName("", "queue-copy"); +queue:create($name); +queue:push($name, <a/>); +queue:push($name, <b/>); +queue:copy($nameCopy, $name); +queue:push($nameCopy, <c/>); +queue:push($nameCopy, <d/>); +(queue:front($nameCopy), queue:size($nameCopy)) === modified file 'test/Queries/delete1.xq' --- test/Queries/delete1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/delete1.xq 2012-02-29 09:13:26 +0000 @@ -1,7 +1,8 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:create("queue1"); -queue:push("queue1", <a/>); -queue:push("queue1", <b/>); -queue:delete("queue1"); +variable $name := fn:QName("", "queue1"); +queue:create($name); +queue:push($name, <a/>); +queue:push($name, <b/>); +queue:delete($name); queue:available-queues() === modified file 'test/Queries/delete2.xq' --- test/Queries/delete2.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/delete2.xq 2012-02-29 09:13:26 +0000 @@ -1,4 +1,5 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:delete("queue1"); -queue:empty("queue1") +variable $name := fn:QName("", "queue1"); +queue:delete($name); +queue:empty($name) === modified file 'test/Queries/empty1.xq' --- test/Queries/empty1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/empty1.xq 2012-02-29 09:13:26 +0000 @@ -1,13 +1,14 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; +variable $name := fn:QName("", "queue1"); ( -queue:create("queue1"), -queue:push("queue1", <a/>), -queue:push("queue1", <b/>), -queue:empty("queue1"), -queue:pop("queue1"), -queue:pop("queue1"), -queue:empty("queue1"), -queue:delete("queue1"), -queue:empty("queue1") + queue:create($name), + queue:push($name, <a/>), + queue:push($name, <b/>), + queue:empty($name), + queue:pop($name), + queue:pop($name), + queue:empty($name), + queue:delete($name), + queue:empty($name) ) \ No newline at end of file === modified file 'test/Queries/front1.xq' --- test/Queries/front1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/front1.xq 2012-02-29 09:13:26 +0000 @@ -1,6 +1,7 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:create("queue1"); -queue:push("queue1", <a/>); -queue:push("queue1", <b/>); -queue:front("queue1") \ No newline at end of file +variable $name := fn:QName("", "queue1"); +queue:create($name); +queue:push($name, <a/>); +queue:push($name, <b/>); +queue:front($name) \ No newline at end of file === modified file 'test/Queries/pop1.xq' --- test/Queries/pop1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/pop1.xq 2012-02-29 09:13:26 +0000 @@ -1,4 +1,5 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:create("queue1"); -queue:pop("queue1") \ No newline at end of file +variable $name := fn:QName("", "queue1"); +queue:create($name); +queue:pop($name) \ No newline at end of file === modified file 'test/Queries/pop2.xq' --- test/Queries/pop2.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/pop2.xq 2012-02-29 09:13:26 +0000 @@ -1,6 +1,7 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:create("queue1"); -queue:push("queue1", <a/>); -queue:push("queue1", <b/>); -queue:pop("queue1") \ No newline at end of file +variable $name := fn:QName("", "queue1"); +queue:create($name); +queue:push($name, <a/>); +queue:push($name, <b/>); +queue:pop($name) \ No newline at end of file === modified file 'test/Queries/push1.xq' --- test/Queries/push1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/push1.xq 2012-02-29 09:13:26 +0000 @@ -1,11 +1,12 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; +variable $name := fn:QName("", "queue1"); ( -queue:create("queue1"), -queue:push("queue1", <a/>), -queue:push("queue1", <b/>), -queue:pop("queue1"), -queue:push("queue1", <c/>), -queue:push("queue1", <d/>), -queue:pop("queue1") + queue:create($name), + queue:push($name, <a/>), + queue:push($name, <b/>), + queue:pop($name), + queue:push($name, <c/>), + queue:push($name, <d/>), + queue:pop($name) ) === modified file 'test/Queries/push2.xq' --- test/Queries/push2.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/push2.xq 2012-02-29 09:13:26 +0000 @@ -1,12 +1,13 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; +variable $name := fn:QName("", "queue1"); ( -queue:create("queue1"), -queue:push("queue1", <a/>), -queue:push("queue1", <b/>), -queue:pop("queue1"), -queue:create("queue1"), -queue:push("queue1", <c/>), -queue:push("queue1", <d/>), -queue:pop("queue1") + queue:create($name), + queue:push($name, <a/>), + queue:push($name, <b/>), + queue:pop($name), + queue:create($name), + queue:push($name, <c/>), + queue:push($name, <d/>), + queue:pop($name) ) === modified file 'test/Queries/size1.xq' --- test/Queries/size1.xq 2012-02-02 18:48:59 +0000 +++ test/Queries/size1.xq 2012-02-29 09:13:26 +0000 @@ -1,9 +1,10 @@ import module namespace queue = "http://www.zorba-xquery.com/modules/store/data-structures/queue"; -queue:create("queue1"); -queue:push("queue1", <a/>); -queue:push("queue1", <b/>); -queue:pop("queue1"); -queue:push("queue1", <c/>); -queue:push("queue1", <d/>); -queue:size("queue1") +variable $name := fn:QName("", "queue1"); +queue:create($name); +queue:push($name, <a/>); +queue:push($name, <b/>); +queue:pop($name); +queue:push($name, <c/>); +queue:push($name, <d/>); +queue:size($name)
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp