<commit_before>#!/bin/bash

#
# Functions used by different quack scripts
#

# Input: id initialValue
# Output: lockname
function createCounter() {
    local ID="$1"
    local INITIAL="$2"
    pushd `dirname $0` > /dev/null
    local LOCKNAME="`pwd`/lock.${ID}_$$"
    popd > /dev/null
    local COUNTFILE="${LOCKNAME}.counter"
    if [ "." == ".$INITIAL" ]; then
        local INITIAL=1
    fi
    echo "$INITIAL" > $COUNTFILE
    echo "$LOCKNAME"
}
export -f createCounter

# Input: lockname delta
# Output: Old counter from lock file + 1
function addDeltaGetCounter() {
    local LOCKNAME="$1"
    local DELTA="$2"

    if [ "." == ".$LOCKNAME" ]; then
        echo "threadedCounter: The lockname must be specified" 1>&2
        exit
    fi
    local COUNTFILE="${LOCKNAME}.counter"

    # http://stackoverflow.com/questions/8231847/bash-script-to-count-number-of-times-script-has-run
    mkdir $LOCKNAME 2> /dev/null
    while [[ $? -ne 0 ]] ; do
        sleep 0.1
        mkdir $LOCKNAME 2> /dev/null
    done
    local COUNTER=`cat "$COUNTFILE"`
    local COUNTER=$((COUNTER+DELTA))
    echo $COUNTER > "$COUNTFILE"
    rm -rf $LOCKNAME
    echo $COUNTER
}
export -f addDeltaGetCounter

# Input: lockname
# Output: Old counter from lock file + 1
function addGetCounter() {
    addDeltaGetCounter "$1" 1
}
export -f addGetCounter

# Removed old count files
function deleteCount() {
    local LOCKNAME="$1"
    if [ "." == ".$LOCKNAME" ]; then
        echo "deleteCount: The lockname must be specified" 1>&2
        exit
    fi<commit_msg>Added helper for simple query of synchronized counter<commit_after>#!/bin/bash

#
# Functions used by different quack scripts
#

# Input: id initialValue
# Output: lockname
function createCounter() {
    local ID="$1"
    local INITIAL="$2"
    pushd `dirname $0` > /dev/null
    local LOCKNAME="`pwd`/lock.${ID}_$$"
    popd > /dev/null
    local COUNTFILE="${LOCKNAME}.counter"
    if [ "." == ".$INITIAL" ]; then
        local INITIAL=1
    fi
    echo "$INITIAL" > $COUNTFILE
    echo "$LOCKNAME"
}
export -f createCounter

# Input: lockname delta
# Output: Old counter from lock file + 1
function addDeltaGetCounter() {
    local LOCKNAME="$1"
    local DELTA="$2"

    if [ "." == ".$LOCKNAME" ]; then
        echo "threadedCounter: The lockname must be specified" 1>&2
        exit
    fi
    local COUNTFILE="${LOCKNAME}.counter"

    # http://stackoverflow.com/questions/8231847/bash-script-to-count-number-of-times-script-has-run
    mkdir $LOCKNAME 2> /dev/null
    while [[ $? -ne 0 ]] ; do
        sleep 0.1
        mkdir $LOCKNAME 2> /dev/null
    done
    local COUNTER=`cat "$COUNTFILE"`
    local COUNTER=$((COUNTER+DELTA))
    echo $COUNTER > "$COUNTFILE"
    rm -rf $LOCKNAME
    echo $COUNTER
}
export -f addDeltaGetCounter

# Input: lockname
# Output: Old counter from lock file + 1
function addGetCounter() {
    addDeltaGetCounter "$1" 1
}
export -f addGetCounter

# Input: lockname
# Output: Old counter from lock file
function getCounter() {
    addDeltaGetCounter "$1" 0
}
export -f getCounter

# Removed old count files
function deleteCount() {
    local LOCKNAME="$1"
    if [ "." == ".$LOCKNAME" ]; then
        echo "deleteCount: The lockname must be specified" 1>&2
        exit
    fi
{'fraction_non_alphanumeric': 0.13316968395213255, 'fraction_numerical': 0.01718318502608162, 'mean_word_length': 2.927710843373494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6474476', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1057, 'n_words': 308}