| /* | |
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you 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 org.apache.datasketches.tuple.strings; | |
| import static org.apache.datasketches.tuple.Util.stringArrHash; | |
| import java.lang.foreign.MemorySegment; | |
| import org.apache.datasketches.common.ResizeFactor; | |
| import org.apache.datasketches.tuple.UpdatableTupleSketch; | |
| /** | |
| * Extends UpdatableTupleSketch<String[], ArrayOfStringsSummary> | |
| * @author Lee Rhodes | |
| */ | |
| public class ArrayOfStringsTupleSketch extends UpdatableTupleSketch<String[], ArrayOfStringsSummary> { | |
| /** | |
| * Constructs new sketch with default <i>K</i> = 4096 (<i>lgK</i> = 12), default ResizeFactor=X8, | |
| * and default <i>p</i> = 1.0. | |
| */ | |
| public ArrayOfStringsTupleSketch() { | |
| this(12); | |
| } | |
| /** | |
| * Constructs new sketch with default ResizeFactor=X8, default <i>p</i> = 1.0 and given <i>lgK</i>. | |
| * @param lgK Log_base2 of <i>Nominal Entries</i>. | |
| * <a href="{@docRoot}/resources/dictionary.html#nomEntries">See Nominal Entries</a> | |
| */ | |
| public ArrayOfStringsTupleSketch(final int lgK) { | |
| this(lgK, ResizeFactor.X8, 1.0F); | |
| } | |
| /** | |
| * Constructs new sketch with given ResizeFactor, <i>p</i> and <i>lgK</i>. | |
| * @param lgK Log_base2 of <i>Nominal Entries</i>. | |
| * <a href="{@docRoot}/resources/dictionary.html#nomEntries">See Nominal Entries</a> | |
| * @param rf ResizeFactor | |
| * <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a> | |
| * @param p sampling probability | |
| * <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability</a> | |
| */ | |
| public ArrayOfStringsTupleSketch(final int lgK, final ResizeFactor rf, final float p) { | |
| super(1 << lgK, rf.lg(), p, new ArrayOfStringsSummaryFactory()); | |
| } | |
| /** | |
| * Constructs new sketch with given ResizeFactor, <i>p</i>, <i>lgK</i> and update seed. | |
| * @param lgK Log_base2 of <i>Nominal Entries</i>. | |
| * <a href="{@docRoot}/resources/dictionary.html#nomEntries">See Nominal Entries</a> | |
| * @param rf ResizeFactor | |
| * <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a> | |
| * @param p sampling probability | |
| * <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability</a> | |
| * @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a> | |
| */ | |
| public ArrayOfStringsTupleSketch(final int lgK, final ResizeFactor rf, final float p, final long seed) { | |
| super(1 << lgK, rf.lg(), p, new ArrayOfStringsSummaryFactory(), seed); | |
| } | |
| /** | |
| * Constructs this sketch from a MemorySegment image, which must be from an ArrayOfStringsTupleSketch, and | |
| * usually with data. | |
| * @param seg the given MemorySegment | |
| * @deprecated As of 3.0.0, heapifying an UpdatableTupleSketch is deprecated. | |
| * This capability will be removed in a future release. | |
| * Heapifying a CompactTupleSketch is not deprecated. | |
| */ | |
| @Deprecated | |
| public ArrayOfStringsTupleSketch(final MemorySegment seg) { | |
| super(seg, new ArrayOfStringsSummaryDeserializer(), new ArrayOfStringsSummaryFactory()); | |
| } | |
| /** | |
| * Copy Constructor | |
| * @param sketch the sketch to copy | |
| */ | |
| public ArrayOfStringsTupleSketch(final ArrayOfStringsTupleSketch sketch) { | |
| super(sketch); | |
| } | |
| /** | |
| * @return a deep copy of this sketch | |
| */ | |
| @Override | |
| public ArrayOfStringsTupleSketch copy() { | |
| return new ArrayOfStringsTupleSketch(this); | |
| } | |
| /** | |
| * Updates the sketch with String arrays for both key and value. | |
| * @param strArrKey the given String array key | |
| * @param strArr the given String array value | |
| */ | |
| public void update(final String[] strArrKey, final String[] strArr) { | |
| super.update(stringArrHash(strArrKey), strArr); | |
| } | |
| } |