aboutsummaryrefslogtreecommitdiffstats
path: root/src/comparable
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-01-20 00:17:53 +0100
committerMattias Andrée <maandree@operamail.com>2014-01-20 00:17:53 +0100
commitde6791a184f397bb75ccf3d3ebee213f3b959a6d (patch)
treee67b936b0b31fa390da26b85c032c594cac3f5eb /src/comparable
parentadd legal files (diff)
downloadalgorithms-and-data-structures-de6791a184f397bb75ccf3d3ebee213f3b959a6d.tar.gz
algorithms-and-data-structures-de6791a184f397bb75ccf3d3ebee213f3b959a6d.tar.bz2
algorithms-and-data-structures-de6791a184f397bb75ccf3d3ebee213f3b959a6d.tar.xz
add MinMax
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/comparable')
-rw-r--r--src/comparable105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/comparable b/src/comparable
new file mode 100644
index 0000000..51762d3
--- /dev/null
+++ b/src/comparable
@@ -0,0 +1,105 @@
+# -*- shell-script -*-
+
+Tparam=""
+Targ=""
+function T-array
+{
+ elems=""
+ for elem in "$@"; do
+ elems="${elems:+${elems}, }${elem}"
+ done
+ if [ $T = T ]; then
+ echo "((${T}[])(new Object[] { ${elems} }))"
+ else
+ echo "(new ${T}[] { ${elems} })"
+ fi
+}
+if [ $T = boolean ]; then
+ function greater
+ { echo "($1) & !($2)"
+ }
+ function greater=
+ { echo "($1) | !($2)"
+ }
+ function =
+ { echo "($1) == ($2)"
+ }
+ function not=
+ { echo "($1) ^ ($2)"
+ }
+ function less=
+ { echo "!($1) | ($2)"
+ }
+ function less
+ { echo "!($1) & ($2)"
+ }
+elif [ $T = T ] || [ $T = T+ ]; then
+ if [ $T = T ]; then
+ Tparam="<T> "
+ Targ=", Comparator<T> comparator"
+ function greater
+ { echo "comparator.compare($1, $2) > 0"
+ }
+ function greater=
+ { echo "comparator.compare($1, $2) >= 0"
+ }
+ function =
+ { echo "comparator.compare($1, $2) == 0"
+ }
+ function not=
+ { echo "comparator.compare($1, $2) != 0"
+ }
+ function less=
+ { echo "comparator.compare($1, $2) <= 0"
+ }
+ function less
+ { echo "comparator.compare($1, $2) < 0"
+ }
+ else
+ Tparam="<T extends Comparable<? super T>> "
+ Targ=""
+ function greater
+ { echo "($1).compareTo($2) > 0"
+ }
+ function greater=
+ { echo "($1).compareTo($2) >= 0"
+ }
+ function =
+ { echo "($1).compareTo($2) == 0"
+ }
+ function not=
+ { echo "($1).compareTo($2) != 0"
+ }
+ function less=
+ { echo "($1).compareTo($2) <= 0"
+ }
+ function less
+ { echo "($1).compareTo($2) < 0"
+ }
+ T=T
+ fi
+else
+ function greater
+ { echo "($1) > ($2)"
+ }
+ function greater=
+ { echo "($1) >= ($2)"
+ }
+ function =
+ { echo "($1) == ($2)"
+ }
+ function not=
+ { echo "($1) != ($2)"
+ }
+ function less=
+ { echo "($1) <= ($2)"
+ }
+ function less
+ { echo "($1) < ($2)"
+ }
+fi
+function fun
+{
+ echo "${Tparam}${1} ${2}(${3}${Targ})"
+}
+