#!/bin/bash

declare -A ht
declare -i i

bits=$1

if [[ ! -a $bits ]]; then
  echo "USAGE: $0 [bits file]"
  exit 0
fi

# Don't use pipe here to avoid subshell so that
# hash table elements are in main process not a subshell
((i=0))
while read bits; do
  if [ -z "$bits" ]; then
    echo $i
    continue
  fi
  if [[ -n ${ht[$bits]} ]]; then
    echo $i
  else
    ((i++))
    ht[$bits]="$i"
    echo $i
  fi
done < <(cat $bits)

