From 7a59ae84e14ef32a4df08bcfb5b870d6f2b842bf Mon Sep 17 00:00:00 2001 From: Bernhard Date: Fri, 17 Jan 2025 10:28:24 +0100 Subject: [PATCH 1/2] use the index for stuff like cpg.method.fullNameExact(a,b,c) --- .../scala/flatgraph/codegen/CodeSnippets.scala | 16 ++++++++++++---- .../traversals/TraversalCallBase.scala | 17 ++++++++++++----- .../traversals/TraversalCallreprBase.scala | 17 ++++++++++++----- .../traversals/TraversalDeclarationBase.scala | 17 ++++++++++++----- .../TraversalPropertyDispatchType.scala | 17 ++++++++++++----- .../traversals/TraversalPropertyName.scala | 17 ++++++++++++----- .../generic/traversals/TraversalNodeaBase.scala | 17 ++++++++++++----- .../TraversalPropertyStringMandatory.scala | 17 ++++++++++++----- .../traversals/TraversalArtistBase.scala | 17 ++++++++++++----- .../traversals/TraversalPropertyName.scala | 17 ++++++++++++----- .../traversals/TraversalSongBase.scala | 17 ++++++++++++----- .../traversals/TraversalBasenodeBase.scala | 17 ++++++++++++----- .../traversals/TraversalPropertyName.scala | 17 ++++++++++++----- 13 files changed, 156 insertions(+), 64 deletions(-) diff --git a/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala b/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala index 6849df24..87d45e9d 100644 --- a/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala +++ b/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala @@ -126,10 +126,18 @@ object CodeSnippets { |/** | * Traverse to nodes where $nameCamelCase matches one of the elements in `values` exactly. | * */ - |def ${nameCamelCase}Exact(values: $baseType*): Iterator[NodeType] = - | if(values.length == 1) ${nameCamelCase}Exact(values.head) else { - | val valueSet = values.toSet - | traversal.filter{item => valueSet.contains(item.$nameCamelCase)} + |def ${nameCamelCase}Exact(values: $baseType*): Iterator[NodeType] = { + | if(values.length == 1) return ${nameCamelCase}Exact(values.head) + | traversal match { + | case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + | val someNode = init.next + | values.iterator.flatMap{ v => + | flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, $propertyId, v).asInstanceOf[Iterator[NodeType]] + | } + | case _ => + | val valueSet = values.toSet + | traversal.filter{item => valueSet.contains(item.$nameCamelCase)} + | } | } | |/** diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallBase.scala b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallBase.scala index 4c72b830..face704a 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallBase.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallBase.scala @@ -37,12 +37,19 @@ final class TraversalCallBase[NodeType <: nodes.CallBase](val traversal: Iterato /** Traverse to nodes where dispatchType matches one of the elements in `values` exactly. */ - def dispatchTypeExact(values: String*): Iterator[NodeType] = - if (values.length == 1) dispatchTypeExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.dispatchType) } + def dispatchTypeExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return dispatchTypeExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 0, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.dispatchType) } } + } /** Traverse to nodes where dispatchType does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallreprBase.scala b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallreprBase.scala index e3c5d3b4..598e3c3a 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallreprBase.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalCallreprBase.scala @@ -37,12 +37,19 @@ final class TraversalCallreprBase[NodeType <: nodes.CallReprBase](val traversal: /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 1, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalDeclarationBase.scala b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalDeclarationBase.scala index e56c3707..ace414ac 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalDeclarationBase.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalDeclarationBase.scala @@ -37,12 +37,19 @@ final class TraversalDeclarationBase[NodeType <: nodes.DeclarationBase](val trav /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 1, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyDispatchType.scala b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyDispatchType.scala index 6b4e5728..63821bae 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyDispatchType.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyDispatchType.scala @@ -39,12 +39,19 @@ final class TraversalPropertyDispatchType[NodeType <: nodes.StoredNode & nodes.S /** Traverse to nodes where dispatchType matches one of the elements in `values` exactly. */ - def dispatchTypeExact(values: String*): Iterator[NodeType] = - if (values.length == 1) dispatchTypeExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.dispatchType) } + def dispatchTypeExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return dispatchTypeExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 0, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.dispatchType) } } + } /** Traverse to nodes where dispatchType does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyName.scala b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyName.scala index 60c4c82a..232cd57c 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyName.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/codepropertygraphminified/traversals/TraversalPropertyName.scala @@ -38,12 +38,19 @@ final class TraversalPropertyName[NodeType <: nodes.StoredNode & nodes.StaticTyp /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 1, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalNodeaBase.scala b/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalNodeaBase.scala index 6ed4dab0..5ca39f09 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalNodeaBase.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalNodeaBase.scala @@ -157,12 +157,19 @@ final class TraversalNodeaBase[NodeType <: nodes.NodeABase](val traversal: Itera /** Traverse to nodes where stringMandatory matches one of the elements in `values` exactly. */ - def stringMandatoryExact(values: String*): Iterator[NodeType] = - if (values.length == 1) stringMandatoryExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.stringMandatory) } + def stringMandatoryExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return stringMandatoryExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 4, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.stringMandatory) } } + } /** Traverse to nodes where stringMandatory does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalPropertyStringMandatory.scala b/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalPropertyStringMandatory.scala index 7ad68476..4f825bec 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalPropertyStringMandatory.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/generic/traversals/TraversalPropertyStringMandatory.scala @@ -39,12 +39,19 @@ final class TraversalPropertyStringMandatory[NodeType <: nodes.StoredNode & node /** Traverse to nodes where stringMandatory matches one of the elements in `values` exactly. */ - def stringMandatoryExact(values: String*): Iterator[NodeType] = - if (values.length == 1) stringMandatoryExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.stringMandatory) } + def stringMandatoryExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return stringMandatoryExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 4, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.stringMandatory) } } + } /** Traverse to nodes where stringMandatory does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalArtistBase.scala b/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalArtistBase.scala index f7dc7da6..bf20d42f 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalArtistBase.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalArtistBase.scala @@ -37,12 +37,19 @@ final class TraversalArtistBase[NodeType <: nodes.ArtistBase](val traversal: Ite /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 0, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalPropertyName.scala b/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalPropertyName.scala index f21f42cf..c1ba68f2 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalPropertyName.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalPropertyName.scala @@ -38,12 +38,19 @@ final class TraversalPropertyName[NodeType <: nodes.StoredNode & nodes.StaticTyp /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 0, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalSongBase.scala b/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalSongBase.scala index ed75cd35..096fd2e0 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalSongBase.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/gratefuldead/traversals/TraversalSongBase.scala @@ -37,12 +37,19 @@ final class TraversalSongBase[NodeType <: nodes.SongBase](val traversal: Iterato /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 0, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalBasenodeBase.scala b/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalBasenodeBase.scala index e98f8575..e0c4e3c8 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalBasenodeBase.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalBasenodeBase.scala @@ -37,12 +37,19 @@ final class TraversalBasenodeBase[NodeType <: nodes.BaseNodeBase](val traversal: /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 0, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ diff --git a/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalPropertyName.scala b/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalPropertyName.scala index bd614278..d2ba9b88 100644 --- a/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalPropertyName.scala +++ b/test-schemas-domain-classes/src/main/scala/testdomains/hierarchical/traversals/TraversalPropertyName.scala @@ -38,12 +38,19 @@ final class TraversalPropertyName[NodeType <: nodes.StoredNode & nodes.StaticTyp /** Traverse to nodes where name matches one of the elements in `values` exactly. */ - def nameExact(values: String*): Iterator[NodeType] = - if (values.length == 1) nameExact(values.head) - else { - val valueSet = values.toSet - traversal.filter { item => valueSet.contains(item.name) } + def nameExact(values: String*): Iterator[NodeType] = { + if (values.length == 1) return nameExact(values.head) + traversal match { + case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + val someNode = init.next + values.iterator.flatMap { v => + flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, 0, v).asInstanceOf[Iterator[NodeType]] + } + case _ => + val valueSet = values.toSet + traversal.filter { item => valueSet.contains(item.name) } } + } /** Traverse to nodes where name does not match the regular expression `value`. */ From 2ea7acbbffc96610249849abba72e84dedcddd9e Mon Sep 17 00:00:00 2001 From: bbrehm Date: Mon, 20 Jan 2025 16:18:22 +0100 Subject: [PATCH 2/2] Update domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala Co-authored-by: Michael Pollmeier --- .../src/main/scala/flatgraph/codegen/CodeSnippets.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala b/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala index 87d45e9d..c2c23f2a 100644 --- a/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala +++ b/domain-classes-generator/src/main/scala/flatgraph/codegen/CodeSnippets.scala @@ -129,12 +129,12 @@ object CodeSnippets { |def ${nameCamelCase}Exact(values: $baseType*): Iterator[NodeType] = { | if(values.length == 1) return ${nameCamelCase}Exact(values.head) | traversal match { - | case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => + | case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext => | val someNode = init.next - | values.iterator.flatMap{ v => - | flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, $propertyId, v).asInstanceOf[Iterator[NodeType]] + | values.iterator.flatMap { value => + | flatgraph.Accessors.getWithInverseIndex(someNode.graph, someNode.nodeKind, $propertyId, value).asInstanceOf[Iterator[NodeType]] | } - | case _ => + | case _ => | val valueSet = values.toSet | traversal.filter{item => valueSet.contains(item.$nameCamelCase)} | }