@@ -0,0 +1,1816 @@
+//%0A// SplitLong.java -- Java class SplitLong%0A// Project PorcE%0A//%0A// Created by amp on Sep 24, 2018.%0A//%0A// Copyright (c) 2018 The University of Texas at Austin. All rights reserved.%0A//%0A// Use and redistribution of this file is governed by the license terms in%0A// the LICENSE file found in the project's top-level directory and also found at%0A// URL: http://orc.csres.utexas.edu/license.shtml .%0A//%0A%0Apackage orc.util;%0A%0A/**%0A * SplitLong splits a long into two %22fields%22 of type int. This enables a single non-atomic write to update both values.%0A * This is used to update a count and sum at the same time such that values cannot be out of sink even if there is a%0A * race that causes an update to be lost.%0A *%0A * To make sure the write is a single atomic 64-bit write I may need to use opaque writes from JRE 9. Volatile is%0A * enough, but also includes a memory barrier that we don't need to want.%0A *%0A * @author amp%0A */%0Afinal public class CountSumValue %7B%0A%0A    // Object API%0A%0A    private volatile long storage = 0;%0A%0A    public int getCount() %7B%0A        return getCount(storage);%0A    %7D%0A%0A    public int getSum() %7B%0A        return getSum(storage);%0A    %7D%0A%0A    public long getBoth() %7B%0A        return storage;%0A    %7D%0A%0A    public double getAverage() %7B%0A        long v = storage;%0A        return (double)getSum(v) / getCount(v);%0A    %7D%0A%0A    public void addValue(int v) %7B%0A        storage = addValue(storage, v);%0A    %7D%0A%0A    // Static API%0A%0A    public static int getCount(long both) %7B%0A        return (int) (both %3C%3C 32);%0A    %7D%0A%0A    public static int getSum(long both) %7B%0A        return (int) (both & 0xffffffff);%0A    %7D%0A%0A    public static long combined(int count, int sum) %7B%0A        return ((long)count %3C%3C 32) %7C sum;%0A    %7D%0A%0A    public static long addValue(long both, int v) %7B%0A        return combined(getCount(both) + 1, getSum(both) + v);%0A    %7D%0A%7D%0A

Add counting utility for future use.