Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.operator.aggregation.state;
 
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public class HyperLogLogStateFactory
         implements AccumulatorStateFactory<HyperLogLogState>
 {
     @Override
     {
         return new SingleHyperLogLogState();
     }
 
     @Override
     public Class<? extends HyperLogLogStategetSingleStateClass()
     {
         return SingleHyperLogLogState.class;
     }
 
     @Override
     {
         return new GroupedHyperLogLogState();
     }
 
     @Override
     public Class<? extends HyperLogLogStategetGroupedStateClass()
     {
         return GroupedHyperLogLogState.class;
     }
 
     public static class GroupedHyperLogLogState
             extends AbstractGroupedAccumulatorState
             implements HyperLogLogState
     {
         private final ObjectBigArray<HyperLogLoghlls = new ObjectBigArray<>();
         private long size;
 
         @Override
         public void ensureCapacity(long size)
         {
             .ensureCapacity(size);
         }
 
         @Override
         public HyperLogLog getHyperLogLog()
         {
             return .get(getGroupId());
         }
 
         @Override
         public void setHyperLogLog(HyperLogLog value)
         {
             checkNotNull(value"value is null");
             .set(getGroupId(), value);
         }
 
         @Override
         public void addMemoryUsage(int value)
         {
              += value;
         }
 
         @Override
         public long getEstimatedSize()
         {
             return  + .sizeOf();
         }
     }
 
     public static class SingleHyperLogLogState
             implements HyperLogLogState
     {
         private HyperLogLog hll;
 
         @Override
         public HyperLogLog getHyperLogLog()
         {
             return ;
         }
 
         @Override
         public void setHyperLogLog(HyperLogLog value)
        {
             = value;
        }
        @Override
        public void addMemoryUsage(int value)
        {
            // noop
        }
        @Override
        public long getEstimatedSize()
        {
            if ( == null) {
                return 0;
            }
            return .estimatedInMemorySize();
        }
    }
New to GrepCode? Check out our FAQ X