File: topk

package info (click to toggle)
stream-lib 2.9.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,540 kB
  • sloc: java: 7,843; xml: 102; sh: 90; makefile: 6
file content (62 lines) | stat: -rwxr-xr-x 1,249 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash

STREAM_LIB_DIR=${STREAM_LIB_DIR:-./target}
HELP=0

function help () {
	cat <<-HELP
	topk -- Finds the top elements in a stream.
	
	Usage:     $( basename $0 ) [options] [CAPACITY] [RATE]
	
	Finds the top elements in a stream, reporting a summary at the end.
	topk looks for the Stream Summary analytics library at the location
	of the environment variable STREAM_LIB_DIR (default is ./target).
	
	Arguments:
	    CAPACITY        Size of top / k (defaults to 1000)
	    RATE            Report interim summary every RATE elements.
	
	Options:
	    -h              Displays this help.
	
	Stream Lib Dir:     ${STREAM_LIB_DIR}
	
HELP
}

function fail () {
    echo "PREDICTABLE FAILURE. $1"
    if [ "$2" ]; then 
        help
    fi
    exit 1
}

SHIFT=0
function incshift () {
    SHIFT=$(( $SHIFT + ${1:-1} ))
}

for opt in $*; do
    case "$opt" in
        -h | -he | -hel | -help | --h | --he | --hel | --help ) 
            HELP=1 ;;
    esac
done

while getopts "h" opt; do
    case $opt in
        h ) HELP=1; incshift ;;
        # $opt ) B=$OPTARG; incshift 2 ;;
    esac
done
shift $SHIFT

if test $HELP == 1; then 
    help
    exit 0
fi

java -cp "${STREAM_LIB_DIR}"/stream-*SNAPSHOT.jar com.clearspring.analytics.util.TopK $*