aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/lib/unique.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /pkg/utilities/nttools/lib/unique.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'pkg/utilities/nttools/lib/unique.x')
-rw-r--r--pkg/utilities/nttools/lib/unique.x64
1 files changed, 64 insertions, 0 deletions
diff --git a/pkg/utilities/nttools/lib/unique.x b/pkg/utilities/nttools/lib/unique.x
new file mode 100644
index 00000000..ca54f840
--- /dev/null
+++ b/pkg/utilities/nttools/lib/unique.x
@@ -0,0 +1,64 @@
+# UNIQUE -- Find unique rows in a table
+#
+# First, the table is sorted on columns input in the colptr array. The
+# results are stored in the index array. Then each row in the index array
+# is compared to the most recent unique row in the index array, column by
+# column. If any column differs, the row is also considered to be unique.
+# The index array is updated to reflect the new unique row and the number of
+# unique rows is incremented.
+#
+# B.Simon 19-Oct-87 First Code
+# B.Simon 14-Dec-87 Changed to handle table subsets
+# B.Simon 06-Feb-90 Changed to use tbtsrt and tbrcmp
+
+procedure unique (tp, numptr, colptr, nindex, index)
+
+pointer tp # i: Table descriptor
+int numptr # i: Number of column pointers
+pointer colptr[ARB] # i: Array of column pointers
+int nindex # io: Number of unique row indices returned
+int index[ARB] # io: Array of unique indices
+#--
+bool fold
+int order, idx, jdx, n, i
+
+int tbrcmp()
+
+begin
+
+ # Sort the array on the selected columns. The sort is in ascending
+ # order and case sensitive
+
+ fold = false
+ call tbtsrt (tp, numptr, colptr, fold, nindex, index)
+
+ # Search for unique rows
+
+ jdx = 0
+ n = nindex
+ nindex = 0
+
+ do i = 1, n {
+ idx = index[i]
+
+ # First row is always unique
+
+ if (i == 1)
+ order = 1
+ else
+ order = tbrcmp (tp, numptr, colptr, fold, idx, jdx)
+
+ # Update pointer to most recent unique row and modify index
+ # array in place
+
+ if (order != 0) {
+ jdx = idx
+ nindex = nindex + 1
+ index[nindex] = idx
+ }
+ }
+
+ do i = nindex+1, n
+ index[i] = 0
+
+end