private Set<Integer> computeDefaultDimensionsToSkipMaterialization() { Set<Integer> skipDimensions = new HashSet<>(); for (int i = 0; i < _numDimensions; i++) { if (_dimensionDictionaries.get(i).size() > _skipMaterializationCardinalityThreshold) { skipDimensions.add(i); } } return skipDimensions; }
/** * @return map of categorical feature index to number of distinct values of the feature */ public Map<Integer,Integer> getCategoryCounts() { Map<Integer,Integer> counts = new HashMap<>(encodingsForIndex.size()); encodingsForIndex.forEach((k, v) -> counts.put(k, v.size())); return counts; }
private short getFreeBiomeId() { short id = 0; while (id < Short.MAX_VALUE) { if (!biomeShortIdMap.containsKey(id)) { return id; } id++; } throw new IllegalStateException("The maximum number of biomes has been reached: " + biomeShortIdMap.size()); }
/** * @param index feature index * @return number of distinct values of the categorical feature */ public int getValueCount(int index) { return doGetMap(index).size(); }
public int numUsers(){ return getUserIds().size(); }
public int numItems(){ return getItemIds().size(); }
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) @CollectionSize.Require(absent = ZERO) public void testKeySetIteratorRemove() { int initialSize = getNumElements(); Iterator<K> iterator = getMap().keySet().iterator(); iterator.next(); iterator.remove(); assertEquals(initialSize - 1, getMap().size()); assertEquals(initialSize - 1, getMap().inverse().size()); } }
@VisibleForTesting static List<String> getUniqueMetrics(List<TimelineObjectHolder<String, DataSegment>> timelineSegments) { final BiMap<String, Integer> uniqueMetrics = HashBiMap.create(); // Here, we try to retain the order of metrics as they were specified. Metrics are extracted from the recent // segments to olders. // timelineSegments are sorted in order of interval int index = 0; for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { for (String metric : chunk.getObject().getMetrics()) { if (!uniqueMetrics.containsKey(metric)) { uniqueMetrics.put(metric, index++); } } } } final BiMap<Integer, String> orderedMetrics = uniqueMetrics.inverse(); return IntStream.range(0, orderedMetrics.size()) .mapToObj(orderedMetrics::get) .collect(Collectors.toList()); } }
@VisibleForTesting static List<String> getUniqueDimensions( List<TimelineObjectHolder<String, DataSegment>> timelineSegments, @Nullable Set<String> excludeDimensions ) { final BiMap<String, Integer> uniqueDims = HashBiMap.create(); // Here, we try to retain the order of dimensions as they were specified since the order of dimensions may be // optimized for performance. // Dimensions are extracted from the recent segments to olders because recent segments are likely to be queried more // frequently, and thus the performance should be optimized for recent ones rather than old ones. // timelineSegments are sorted in order of interval int index = 0; for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { for (String dimension : chunk.getObject().getDimensions()) { if (!uniqueDims.containsKey(dimension) && (excludeDimensions == null || !excludeDimensions.contains(dimension))) { uniqueDims.put(dimension, index++); } } } } final BiMap<Integer, String> orderedDims = uniqueDims.inverse(); return IntStream.range(0, orderedDims.size()) .mapToObj(orderedDims::get) .collect(Collectors.toList()); }
public void testIdentityKeySetIteratorRemove() { BiMap<Integer, String> bimap = new AbstractBiMap<Integer, String>( new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {}; bimap.put(1, "one"); bimap.put(2, "two"); bimap.put(3, "three"); Iterator<Integer> iterator = bimap.keySet().iterator(); iterator.next(); iterator.next(); iterator.remove(); iterator.next(); iterator.remove(); assertEquals(1, bimap.size()); assertEquals(1, bimap.inverse().size()); }
/** * plus a key to the corresponding map and return the value. * @param input value * @param attrName attribute name * @return inner value */ public static int setId(String input, String attrName){ BiMap<String, Integer> innerMap = getInnerMapping(attrName); if (innerMap.containsKey(input)){ return innerMap.get(input); }else{ int cur = innerMap.size(); innerMap.put(input, cur); return cur; } }
public void testIdentityEntrySetIteratorRemove() { BiMap<Integer, String> bimap = new AbstractBiMap<Integer, String>( new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {}; bimap.put(1, "one"); bimap.put(2, "two"); bimap.put(3, "three"); Iterator<Entry<Integer, String>> iterator = bimap.entrySet().iterator(); iterator.next(); iterator.next(); iterator.remove(); iterator.next(); iterator.remove(); assertEquals(1, bimap.size()); assertEquals(1, bimap.inverse().size()); } }
/** * Creates a rabbit of a random type. * * @param location the location */ public GlowRabbit(Location location) { super(location, EntityType.RABBIT, 3); setSize(0.4F, 0.5F); setRabbitType( Type.values()[ThreadLocalRandom.current().nextInt(rabbitTypeIntegerMap.size())]); }
/** * Process appender data. * * @throws IOException if I/O error occurs during processing */ @Override public void processData() throws IOException { if (conf != null && StringUtils.isNotBlank(conf.get("data.appender.path"))) { inputDataPath = conf.get("dfs.data.dir") + "/" + conf.get("data.appender.path"); LOG.info(inputDataPath); locationArray = new KeyValue[itemIds.size()]; readData(inputDataPath); } }
@SuppressWarnings("unchecked") @MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(ONE) public void testForcePutValuePresent() { getMap().forcePut(k1(), v0()); expectContents(Helpers.mapEntry(k1(), v0())); assertEquals(k1(), getMap().inverse().get(v0())); assertEquals(1, getMap().size()); assertFalse(getMap().containsKey(k0())); }
@SuppressWarnings("unchecked") @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) @CollectionSize.Require(ONE) public void testForcePutNullValuePresent() { initMapWithNullValue(); getMap().forcePut(k1(), null); expectContents(Helpers.mapEntry(k1(), (V) null)); assertFalse(getMap().containsKey(k0())); assertTrue(getMap().containsKey(k1())); assertTrue(getMap().inverse().containsKey(null)); assertNull(getMap().get(k1())); assertEquals(k1(), getMap().inverse().get(null)); assertEquals(1, getMap().size()); }
@Test(dependsOnMethods = {"testPersistDatasetUrns"}) public void testGetDatasetUrnFromStateStoreName() throws IOException { GuidDatasetUrnStateStoreNameParser parser = new GuidDatasetUrnStateStoreNameParser(this.testFs, this.jobStateRootDir); Assert.assertEquals(parser.sanitizedNameToDatasetURNMap.size(), 2); Assert.assertTrue(parser.sanitizedNameToDatasetURNMap.inverse().containsKey("dataset1")); Assert.assertTrue(parser.sanitizedNameToDatasetURNMap.inverse().containsKey("dataset2")); Assert.assertEquals(parser.getStateStoreNameFromDatasetUrn("dataset1"), Guid.fromStrings("dataset1").toString()); Assert.assertEquals(parser.getStateStoreNameFromDatasetUrn("dataset2"), Guid.fromStrings("dataset2").toString()); }
@SuppressWarnings("unchecked") @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS}) @CollectionSize.Require(ONE) public void testForcePutNullKeyPresent() { initMapWithNullKey(); getMap().forcePut(null, v1()); expectContents(Helpers.mapEntry((K) null, v1())); assertFalse(getMap().containsValue(v0())); assertTrue(getMap().containsValue(v1())); assertTrue(getMap().inverse().containsKey(v1())); assertNull(getMap().inverse().get(v1())); assertEquals(v1(), getMap().get(null)); assertEquals(1, getMap().size()); }
@SuppressWarnings("unchecked") @MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(ONE) public void testForcePutKeyPresent() { getMap().forcePut(k0(), v1()); expectContents(Helpers.mapEntry(k0(), v1())); assertFalse(getMap().containsValue(v0())); assertNull(getMap().inverse().get(v0())); assertEquals(1, getMap().size()); assertTrue(getMap().containsKey(k0())); }
@SuppressWarnings("unchecked") @MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(SEVERAL) public void testForcePutKeyAndValuePresent() { getMap().forcePut(k0(), v1()); expectContents(Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k2(), v2())); assertEquals(2, getMap().size()); assertFalse(getMap().containsKey(k1())); assertFalse(getMap().containsValue(v0())); }