1
0
Fork 0

fixed issue #1025: Traversal not as expected in undirected graph

This commit is contained in:
Jan Steemann 2014-09-22 23:08:17 +02:00
parent d79792ab1c
commit 9716a482cd
3 changed files with 96 additions and 7 deletions

View File

@ -3,6 +3,8 @@ v2.3.0 (XXXX-XX-XX)
* fixed issue #1027: Stack traces are off-by-one
* fixed issue #1025: Traversal not as expected in undirected graph
* added a _relation function in the general-graph module.
This deprecated _directedRelation and _undirectedRelation.

View File

@ -411,6 +411,26 @@ function SimpleQueryByExampleSuite () {
assertEqual(2, s.a);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: byExample, using _id & sub-attributes
////////////////////////////////////////////////////////////////////////////////
testByExampleIdSubAttributes : function () {
var d, s;
d = collection.save({ _key: "meow", foo: { bar: "baz" } });
s = collection.firstExample({ _id: cn + "/meow", foo: { bar: "baz" } });
assertEqual(d._id, s._id);
assertEqual(d._key, s._key);
assertEqual({ bar: "baz" }, s.foo);
d = collection.save({ _key: "foo", values: [ { foo: "bar", baz: "bam" } ] });
s = collection.firstExample({ _id: cn + "/foo", values: [ { foo: "bar", baz: "bam" } ] });
assertEqual(d._id, s._id);
assertEqual(d._key, s._key);
assertEqual([ { foo: "bar", baz: "bam" } ], s.values);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: byExample, using non existing system attribute
////////////////////////////////////////////////////////////////////////////////

View File

@ -251,6 +251,78 @@ function supportsQuery (idx, attributes) {
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get the type of a document attribute
////////////////////////////////////////////////////////////////////////////////
function docType (value) {
"use strict";
if (value !== undefined && value !== null) {
if (Array.isArray(value)) {
return 'array';
}
switch (typeof(value)) {
case 'boolean':
return 'boolean';
case 'number':
if (isNaN(value) || ! isFinite(value)) {
// not a number => undefined
return 'null';
}
return 'number';
case 'string':
return 'string';
case 'object':
return 'object';
}
}
return 'null';
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks whether or not the example is contained in the document
////////////////////////////////////////////////////////////////////////////////
function isContained (doc, example) {
"use strict";
var eType = docType(example);
var dType = docType(doc);
if (eType !== dType) {
return false;
}
var i;
if (eType === 'object') {
for (i in example) {
if (example.hasOwnProperty(i)) {
if (! doc.hasOwnProperty(i) ||
! isContained(doc[i], example[i])) {
return false;
}
}
}
}
else if (eType === 'array') {
if (doc.length !== example.length) {
return false;
}
for (i = 0; i < doc.length; ++i) {
if (! isContained(doc[i], example[i])) {
return false;
}
}
}
else if (doc !== example) {
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief query-by scan or hash index
////////////////////////////////////////////////////////////////////////////////
@ -305,13 +377,8 @@ function byExample (data) {
// we have used the primary index to look up the document
// now we need to post-filter because non-indexed values might not have matched
for (k in example) {
if (example.hasOwnProperty(k)) {
if (doc[k] !== example[k]) {
doc = null;
break;
}
}
if (! isContained(doc, example)) {
doc = null;
}
}
catch (e) {