XQuery compare order of two sequencesDividing the screen in two halves using LinearLayoutFinding the minimum...
How to tag distinct options/entities without giving any an implicit priority or suggested order?
Groups acting on trees
Slow moving projectiles from a hand-held weapon - how do they reach the target?
How should I handle players who ignore the session zero agreement?
What is this metal M-shaped device for?
Why don't American passenger airlines operate dedicated cargo flights any more?
Is a debit card dangerous for an account with low balance and no overdraft protection?
why a subspace is closed?
How to convert a ListContourPlot into primitive usable with Graphics3D?
If I sold a PS4 game I owned the disc for, can I reinstall it digitally?
What makes the Forgotten Realms "forgotten"?
Why did this image turn out darker?
What to do if authors don't respond to my serious concerns about their paper?
Every character has a name - does this lead to too many named characters?
Does fast page mode apply to ROM?
What is better: yes / no radio, or simple checkbox?
Grade 10 Analytic Geometry Question 23- Incredibly hard
What is the purpose of easy combat scenarios that don't need resource expenditure?
Can you earn endless XP using a Flameskull and its self-revival feature?
Does Windows 10's telemetry include sending *.doc files if Word crashed?
Citing paywalled articles accessed via illegal web sharing
Dilemma of explaining to interviewer that he is the reason for declining second interview
Strange Sign on Lab Door
Quenching swords in dragon blood; why?
XQuery compare order of two sequences
Dividing the screen in two halves using LinearLayoutFinding the minimum of two numbersMerging two XMLs together in PythonMerging tags in two XML files with same attributes and different contentUsing LINQ to output SQL data from two tables into XMLOpening the same CSV file in two different ways in order to transform data in one column and update original CSV using PythonFunctional-style Cocoa XML serializer and object mapperSQL query to compare two XML columnsRecursive function to compare XML files using MSXML DOM
$begingroup$
I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.
This is best illustrated with an example
E.G.
let $baseSequence := ('a','b','c'..'x','y','z')
Tested against
('a','b','c') => true
appears in the same order in $baseSequence
('a','b','a') => false
is not in the same order in $baseSequence
('c','h','x','y') => true
appears in the same order in $baseSequence
I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?
declare function local:testOrder($baseSequence, $testSequence, $position) {
let $itemPosition :=
if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
return
if ($itemPosition > $position) then (
local:testOrder($baseSequence, tail($testSequence), $itemPosition)
) else (
count($testSequence) = 0
)
};
(:Test cases:)
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('a','c','e','h','w')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return true
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('f','d','l','m','n')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return false
xml xquery
$endgroup$
add a comment |
$begingroup$
I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.
This is best illustrated with an example
E.G.
let $baseSequence := ('a','b','c'..'x','y','z')
Tested against
('a','b','c') => true
appears in the same order in $baseSequence
('a','b','a') => false
is not in the same order in $baseSequence
('c','h','x','y') => true
appears in the same order in $baseSequence
I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?
declare function local:testOrder($baseSequence, $testSequence, $position) {
let $itemPosition :=
if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
return
if ($itemPosition > $position) then (
local:testOrder($baseSequence, tail($testSequence), $itemPosition)
) else (
count($testSequence) = 0
)
};
(:Test cases:)
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('a','c','e','h','w')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return true
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('f','d','l','m','n')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return false
xml xquery
$endgroup$
add a comment |
$begingroup$
I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.
This is best illustrated with an example
E.G.
let $baseSequence := ('a','b','c'..'x','y','z')
Tested against
('a','b','c') => true
appears in the same order in $baseSequence
('a','b','a') => false
is not in the same order in $baseSequence
('c','h','x','y') => true
appears in the same order in $baseSequence
I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?
declare function local:testOrder($baseSequence, $testSequence, $position) {
let $itemPosition :=
if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
return
if ($itemPosition > $position) then (
local:testOrder($baseSequence, tail($testSequence), $itemPosition)
) else (
count($testSequence) = 0
)
};
(:Test cases:)
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('a','c','e','h','w')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return true
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('f','d','l','m','n')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return false
xml xquery
$endgroup$
I have written a function in XQuery 3.0 (using BaseX) which tests a base sequence against a test sequence, with the goal of determining if the items in the test sequence appear in the same order as the base sequence.
This is best illustrated with an example
E.G.
let $baseSequence := ('a','b','c'..'x','y','z')
Tested against
('a','b','c') => true
appears in the same order in $baseSequence
('a','b','a') => false
is not in the same order in $baseSequence
('c','h','x','y') => true
appears in the same order in $baseSequence
I would like to know if there are any improvements on the function I have written for this, or is there a better way of doing this?
declare function local:testOrder($baseSequence, $testSequence, $position) {
let $itemPosition :=
if(count($testSequence) = 0) then (32768) else (index-of($baseSequence, head($testSequence)))
return
if ($itemPosition > $position) then (
local:testOrder($baseSequence, tail($testSequence), $itemPosition)
) else (
count($testSequence) = 0
)
};
(:Test cases:)
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('a','c','e','h','w')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return true
let $baseSequence := ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
let $testAgainst := ('f','d','l','m','n')
return local:testOrder($baseSequence, $testAgainst, 0)
Would return false
xml xquery
xml xquery
edited 10 hours ago
200_success
130k16153417
130k16153417
asked 10 hours ago
swshaunswshaun
486
486
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):
declare function local:testOrder2($baseSequence, $testSequence) {
let $positions := $testSequence ! index-of($baseSequence, .)
return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
};
Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!
New contributor
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214571%2fxquery-compare-order-of-two-sequences%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):
declare function local:testOrder2($baseSequence, $testSequence) {
let $positions := $testSequence ! index-of($baseSequence, .)
return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
};
Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!
New contributor
$endgroup$
add a comment |
$begingroup$
There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):
declare function local:testOrder2($baseSequence, $testSequence) {
let $positions := $testSequence ! index-of($baseSequence, .)
return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
};
Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!
New contributor
$endgroup$
add a comment |
$begingroup$
There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):
declare function local:testOrder2($baseSequence, $testSequence) {
let $positions := $testSequence ! index-of($baseSequence, .)
return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
};
Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!
New contributor
$endgroup$
There is a more concise possible approach if you, first, convert the test sequence into the corresponding positions in the base sequence, then, substract each position to the next one (replace "ge 0" with "gt 0" if duplicates are not allowed):
declare function local:testOrder2($baseSequence, $testSequence) {
let $positions := $testSequence ! index-of($baseSequence, .)
return min(for $pos at $index in tail($positions) return $pos - $positions[$index]) ge 0
};
Your recursive approach will stop at the first disorder detection so, depending on inputs, it might be faster!
New contributor
edited 2 mins ago
New contributor
answered 4 hours ago
Alain CouthuresAlain Couthures
101
101
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214571%2fxquery-compare-order-of-two-sequences%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown