class GiniImpurityMeasure implements ImpurityMeasure<GiniImpurityMeasure> {

    @Override public double impurity() {
        long leftCnt = 0;
        long rightCnt = 0;

        double leftImpurity = 0;
        double rightImpurity = 0;

        for (long e : left)
            leftCnt += e;

        for (long e : right)
            rightCnt += e;

        if (leftCnt > 0)
            for (long e : left)
                leftImpurity += Math.pow(e, 2) / leftCnt;

        if (rightCnt > 0)
            for (long e : right)
                rightImpurity += Math.pow(e, 2) / rightCnt;

        return -(leftImpurity + rightImpurity);
    }

      GiniImpurityMeasure(long[] left, long[] right);

}