diff options
author | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2019-01-31 11:16:09 -0500 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2019-02-04 10:22:46 -0500 |
commit | 74f8b56fcc3c0193c83e625fcc4148060051e54b (patch) | |
tree | 6868e3473ab70639bf87a48a63fdaa7dab0ad635 /core | |
parent | 9af38261b9b90584d6da4868bafe1ed023c2ca89 (diff) | |
download | tame-74f8b56fcc3c0193c83e625fcc4148060051e54b.tar.gz tame-74f8b56fcc3c0193c83e625fcc4148060051e54b.tar.bz2 tame-74f8b56fcc3c0193c83e625fcc4148060051e54b.zip |
Use some modern shorthands for core/vector/{table,filter}
Just trying to clean up a little as I go to start to make it easier
to understand.
* core/vector/filter.xml: Use _when-*_ templates and c:recurse.
* core/vector/table.xml: Likewise.
Diffstat (limited to 'core')
-rw-r--r-- | core/vector/filter.xml | 93 | ||||
-rw-r--r-- | core/vector/table.xml | 79 |
2 files changed, 51 insertions, 121 deletions
diff --git a/core/vector/filter.xml b/core/vector/filter.xml index c662d95..30cee02 100644 --- a/core/vector/filter.xml +++ b/core/vector/filter.xml @@ -24,6 +24,7 @@ desc="Filtering Vectors and Matrices"> <import package="../base" /> + <import package="../when" /> <import package="list" /> @@ -70,11 +71,7 @@ perform a linear search (if the dataset is large enough and the column value is relatively distinct) --> <c:case> - <c:when name="seq"> - <c:eq> - <c:value-of name="TRUE" /> - </c:eq> - </c:when> + <t:when-eq name="seq" value="TRUE" /> <c:apply name="bisect" matrix="matrix" col="col" val="val"> <c:arg name="start"> @@ -145,17 +142,8 @@ <c:value name="over" type="boolean" desc="Did we pass the potential value in a sorted list?"> <c:value-of name="TRUE"> - <c:when name="seq"> - <c:eq> - <c:value-of name="TRUE" /> - </c:eq> - </c:when> - - <c:when name="curval"> - <c:gt> - <c:value-of name="val" /> - </c:gt> - </c:when> + <t:when-eq name="seq" value="TRUE" /> + <t:when-gt name="curval" value="val" /> </c:value-of> </c:value> </c:values> @@ -163,26 +151,16 @@ <c:cases> <!-- if we're done filtering, then return an empty set --> <c:case> - <c:when name="start"> - <c:gt> - <c:value-of name="end" /> - </c:gt> - </c:when> + <t:when-gt name="start" value="end" /> - <!-- empty set --> <c:vector /> </c:case> <!-- if the data is sequential and the next element is over the requested value, then we're done --> <c:case> - <c:when name="over"> - <c:eq> - <c:value-of name="TRUE" /> - </c:eq> - </c:when> + <t:when-eq name="over" value="TRUE" /> - <!-- empty set --> <c:vector /> </c:case> @@ -223,11 +201,7 @@ <c:cases> <c:case> - <c:when name="cur"> - <c:eq> - <c:value-of name="val" /> - </c:eq> - </c:when> + <t:when-eq name="cur" value="val" /> <c:cons> <c:value-of name="matrix"> @@ -329,16 +303,13 @@ <c:cases> <!-- give up if we've reached our gap limit --> <c:case> - <c:when name="gap"> - <c:lte> - <c:value-of name="MFILTER_BISECT_GAP_MAX" /> - </c:lte> - </c:when> + <t:when-lte name="gap" value="MFILTER_BISECT_GAP_MAX" /> <!-- we tried our best; return our current position --> <c:value-of name="start" /> </c:case> + <!-- we have not yet reached our gap limit; keep going --> <c:otherwise> <c:let> @@ -378,22 +349,14 @@ <c:cases> <!-- if the middle value is lower than our value, then take the upper half --> <c:case> - <c:when name="mid"> - <c:lt> - <c:value-of name="val" /> - </c:lt> - </c:when> + <t:when-lt name="mid" value="val" /> <c:recurse start="mid_index" /> </c:case> <!-- similarily, take the lower half if we over-shot --> <c:case> - <c:when name="mid"> - <c:gt> - <c:value-of name="val" /> - </c:gt> - </c:when> + <t:when-gt name="mid" value="val" /> <c:recurse end="mid_index" /> </c:case> @@ -460,24 +423,14 @@ <c:cases> <!-- if we have no more indexes to check, then we're done --> <c:case> - <c:when name="i"> - <c:eq> - <c:const value="0" - desc="Did we check the final (first) index?" /> - </c:eq> - </c:when> - - <!-- well, then, we're done --> + <t:when-eq name="i" value="#0" /> + <c:value-of name="i" /> </c:case> <!-- if the previous column value is the same value, then continue checking --> <c:case> - <c:when name="prev"> - <c:eq> - <c:value-of name="val" /> - </c:eq> - </c:when> + <t:when-eq name="prev" value="val" /> <c:recurse> <c:arg name="i"> @@ -507,23 +460,7 @@ <c:cases> <!-- if masked --> <c:case> - <!-- no index provided --> - <unless name="@index@"> - <c:when name="@name@"> - <c:eq> - <c:value-of name="FALSE" /> - </c:eq> - </c:when> - </unless> - - <!-- index provided --> - <if name="@index@"> - <c:when name="@name@" index="@index@"> - <c:eq> - <c:value-of name="FALSE" /> - </c:eq> - </c:when> - </if> + <t:when-eq name="@name@" index="@index@" value="FALSE" /> <!-- TODO: configurable mask via meta and/or param --> <c:value-of name="TABLE_WHEN_MASK_VALUE" /> diff --git a/core/vector/table.xml b/core/vector/table.xml index 96b2517..268dce6 100644 --- a/core/vector/table.xml +++ b/core/vector/table.xml @@ -28,6 +28,7 @@ <!-- since templates are inlined, we need to make these symbols available to avoid terrible confusion --> <import package="../numeric/common" export="true"/> + <import package="../when" export="true"/> <import package="common" export="true" /> <import package="filter" export="true" /> <import package="matrix" export="true" /> @@ -314,33 +315,36 @@ <text>_RATE_TABLE</text> </param> - <c:apply name="_mquery"> - <c:arg name="matrix"> - <c:value-of name="@matrix@" /> - </c:arg> - - <c:arg name="criteria"> - <c:vector> - <param-copy name="@values@"> - <param-meta name="table_basename" value="@matrix@" /> - </param-copy> - </c:vector> - </c:arg> - <c:arg name="i"> - <!-- begin with the last predicate (due to the way we'll recurse, it - will be applied *last* --> - <t:dec> - <c:length-of> - <c:vector> - <param-copy name="@values@"> - <param-meta name="table_basename" value="@matrix@" /> - </param-copy> - </c:vector> - </c:length-of> - </t:dec> - </c:arg> - </c:apply> + <c:let> + <c:values> + <c:value name="_qparams" type="integer" set="matrix" + desc="Query parameters"> + <c:vector> + <param-copy name="@values@"> + <param-meta name="table_basename" value="@matrix@" /> + </param-copy> + </c:vector> + </c:value> + </c:values> + + + <c:apply name="_mquery" matrix="@matrix@"> + <c:arg name="criteria"> + <c:value-of name="_qparams" /> + </c:arg> + + <c:arg name="i"> + <!-- begin with the last predicate (due to the way we'll recurse, it + will be applied *last* --> + <t:dec> + <c:length-of> + <c:value-of name="_qparams" /> + </c:length-of> + </t:dec> + </c:arg> + </c:apply> + </c:let> </template> @@ -417,38 +421,27 @@ <c:cases> <c:case> - <c:when name="i"> - <c:eq> - <!-- it's important that we allow index 0, since that is a valid - predicate --> - <c:const value="-1" type="integer" desc="We're done." /> - </c:eq> - </c:when> + <!-- it's important that we allow index 0, since that is a valid + predicate --> + <t:when-eq name="i" value="#-1" /> <!-- we're done; stick with the result --> <c:value-of name="matrix" /> </c:case> + <c:otherwise> <c:apply name="mfilter"> <!-- matrix to search --> <c:arg name="matrix"> <!-- >> recursion happens here << --> - <c:apply name="_mquery"> - <c:arg name="matrix"> - <c:value-of name="matrix" /> - </c:arg> - - <c:arg name="criteria"> - <c:value-of name="criteria" /> - </c:arg> - + <c:recurse> <c:arg name="i"> <t:dec> <c:value-of name="i" /> </t:dec> </c:arg> - </c:apply> + </c:recurse> </c:arg> <!-- field (column) --> |