org.agrona.collections.IntHashSet Java Examples

The following examples show how to use org.agrona.collections.IntHashSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OtfValidator.java    From artio with Apache License 2.0 6 votes vote down vote up
public MessageControl onComplete()
{
    final IntHashSet missingFields = requiredFields.values(messageType).difference(fieldsForMessage);
    if (missingFields == null)
    {
        return delegate.onComplete();
    }
    else
    {
        for (final int value : missingFields)
        {
            delegate.onError(MISSING_REQUIRED_FIELD, messageType, value, stringField);
        }
    }
    return MessageControl.CONTINUE;
}
 
Example #2
Source File: ChannelControllerRouter.java    From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void routeIncrementalComplete(IntHashSet securityIds, MdpMessage mdpMessage, long msgSeqNum) {
    for (int securityId : securityIds) {
        InstrumentController instrumentController = instrumentManager.getInstrumentController(securityId);
        if (instrumentController != null) {
            instrumentController.handleIncrementalComplete(mdpMessage, msgSeqNum);
        }
    }
}
 
Example #3
Source File: LongDictionaryTest.java    From artio with Apache License 2.0 5 votes vote down vote up
@Test
public void buildsValidationDictionaryForAllFields()
{
    final LongDictionary longDictionary = LongDictionary.allFields(data);
    final IntHashSet heartbeat = longDictionary.values('0');

    assertThat(heartbeat, hasItem(115));
    assertThat(heartbeat, hasItem(112));
    assertThat(heartbeat, hasSize(2));

    assertTrue(longDictionary.contains('0', 115));
    assertTrue(longDictionary.contains('0', 112));
}
 
Example #4
Source File: LongDictionaryTest.java    From artio with Apache License 2.0 5 votes vote down vote up
@Test
public void buildsValidationDictionaryForRequiredFields()
{
    final LongDictionary longDictionary = LongDictionary.requiredFields(data);
    final IntHashSet heartbeat = longDictionary.values('0');

    assertThat(heartbeat, hasItem(115));
    assertThat(heartbeat, hasSize(1));
    assertTrue(longDictionary.contains('0', 115));
}
 
Example #5
Source File: ConstantGeneratorTest.java    From artio with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGenerateAllFieldsSet() throws Exception
{
    final Object allFieldsField = getField(constants, "ALL_FIELDS");
    assertThat(allFieldsField, instanceOf(IntHashSet.class));

    @SuppressWarnings("unchecked") final Set<Integer> allFields = (Set<Integer>)allFieldsField;
    assertThat(allFields, hasItem(123));
    assertThat(allFields, hasItem(124));
    assertThat(allFields, hasItem(35));
    assertThat(allFields, not(hasItem(999)));
}
 
Example #6
Source File: AbstractDecoderGeneratorTest.java    From artio with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGenerateRequiredFieldsDictionary() throws Exception
{
    final Decoder decoder = newHeartbeat();
    final Object allFieldsField = getRequiredFields(decoder);
    assertThat(allFieldsField, instanceOf(IntHashSet.class));

    @SuppressWarnings("unchecked") final Set<Integer> allFields = (Set<Integer>)allFieldsField;
    assertThat(allFields, hasItem(INT_FIELD_TAG));
    assertThat(allFields, not(hasItem(112)));
    assertThat(allFields, not(hasItem(999)));
}
 
Example #7
Source File: OtfParser.java    From artio with Apache License 2.0 5 votes vote down vote up
private int parseGroup(
    final int tag,
    final int valueOffset,
    final int endOfField,
    final int end,
    final IntHashSet groupFields)
{
    final int numberOfElements = string.getNatural(valueOffset, endOfField);

    acceptor.onGroupHeader(tag, numberOfElements);

    if (numberOfElements > 0)
    {
        if (groupBegin(tag, numberOfElements, 0) == STOP)
        {
            return ~endOfField;
        }

        final int position = parseFields(endOfField + 1, end, tag, groupFields, numberOfElements);
        if (position == end)
        {
            if (groupEnd(tag, numberOfElements, numberOfElements - 1) == STOP)
            {
                return ~position;
            }
        }
        return position;
    }

    return endOfField;
}
 
Example #8
Source File: LongDictionary.java    From artio with Apache License 2.0 5 votes vote down vote up
public void putAll(final long key, final int... valuesToAdd)
{
    final IntHashSet values = valuesOrDefault(key);
    for (final int value : valuesToAdd)
    {
        values.add(value);
    }
}
 
Example #9
Source File: ConstantGenerator.java    From artio with Apache License 2.0 5 votes vote down vote up
public void generate()
{
    outputManager.withOutput(CLASS_NAME, (out) ->
    {
        out.append(fileHeader(builderPackage));
        out.append(importFor(IntHashSet.class));
        out.append(importFor(CharArraySet.class));
        out.append(BODY);
        out.append(generateVersion());
        out.append(generateMessageTypes());
        out.append(generateFieldTags());
        out.append(generateAllFieldsDictionary());
        out.append("}\n");
    });
}
 
Example #10
Source File: FixCounters.java    From artio with Apache License 2.0 5 votes vote down vote up
public static IntHashSet lookupCounterIds(
    final FixCountersId counterTypeId, final CountersReader countersReader)
{
    final int requiredTypeId = counterTypeId.id();
    final IntHashSet counterIds = new IntHashSet();
    countersReader.forEach((counterId, typeId, keyBuffer, label) ->
    {
        if (typeId == requiredTypeId)
        {
            counterIds.add(counterId);
        }
    });
    return counterIds;
}
 
Example #11
Source File: Common.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
public void setup(final BenchmarkParams b) throws IOException {
  keySize = intKey ? BYTES : STRING_KEY_LENGTH;
  crc = new CRC32();
  final IntHashSet set = new IntHashSet(num);
  keys = new int[num];
  for (int i = 0; i < num; i++) {
    if (sequential) {
      keys[i] = i;
    } else {
      while (true) {
        int candidateKey = RND.nextInt();
        if (candidateKey < 0) {
          candidateKey *= -1;
        }
        if (!set.contains(candidateKey)) {
          set.add(candidateKey);
          keys[i] = candidateKey;
          break;
        }
      }
    }
  }

  rmdir(TMP_BENCH);
  tmp = create(b, "");
  compact = create(b, "-compacted");
}
 
Example #12
Source File: LongDictionary.java    From artio with Apache License 2.0 4 votes vote down vote up
public IntHashSet values(final long key)
{
    return map.get(key);
}
 
Example #13
Source File: LongDictionary.java    From artio with Apache License 2.0 4 votes vote down vote up
public boolean contains(final long key, final int value)
{
    final IntHashSet fields = values(key);
    return fields != null && fields.contains(value);
}
 
Example #14
Source File: LongDictionary.java    From artio with Apache License 2.0 4 votes vote down vote up
private IntHashSet valuesOrDefault(final long key)
{
    return map.computeIfAbsent(key, ignore -> new IntHashSet(CAPACITY));
}
 
Example #15
Source File: OtfParser.java    From artio with Apache License 2.0 4 votes vote down vote up
private int parseFields(
    final int offset,
    final int end,
    final int groupTag,
    final IntHashSet groupFields,
    final int numberOfElementsInGroup)
{
    int firstFieldInGroup = UNKNOWN;
    int indexOfGroupElement = 0;

    int position = offset;

    while (position < end)
    {
        final int equalsPosition = string.scan(position, end, '=');
        if (!validatePosition(equalsPosition, acceptor))
        {
            return position;
        }

        tag = string.getNatural(position, equalsPosition);
        final int valueOffset = equalsPosition + 1;
        final int endOfField = string.scan(valueOffset, end, START_OF_HEADER);
        if (!validatePosition(endOfField, acceptor))
        {
            return position;
        }

        final int valueLength = endOfField - valueOffset;

        final IntHashSet newGroupFields = groupToField.values(tag);
        if (newGroupFields == null)
        {

            if (insideAGroup(groupTag))
            {
                if (isEndOfGroup(groupFields))
                {
                    groupEnd(groupTag, numberOfElementsInGroup, indexOfGroupElement);
                    return position;
                }
                else
                {
                    // First field first iteration
                    if (firstFieldInGroup == UNKNOWN)
                    {
                        firstFieldInGroup = tag;
                    }
                    // We've seen the first field again - its a new group iteration
                    else if (tag == firstFieldInGroup)
                    {
                        if (groupEnd(groupTag, numberOfElementsInGroup, indexOfGroupElement) == STOP)
                        {
                            return position;
                        }
                        indexOfGroupElement++;
                        if (groupBegin(groupTag, numberOfElementsInGroup, indexOfGroupElement) == STOP)
                        {
                            return position;
                        }
                    }
                }
            }
            final MessageControl control = acceptor.onField(tag, string, valueOffset, valueLength);

            collectImportantFields(equalsPosition, valueOffset, endOfField, valueLength);

            position = endOfField + 1;

            if (control == STOP)
            {
                return ~position;
            }
        }
        else
        {
            if (insideAGroup(groupTag) && isEndOfGroup(groupFields))
            {
                groupEnd(groupTag, numberOfElementsInGroup, indexOfGroupElement);
                return position;
            }
            else
            {
                position = parseGroup(tag, valueOffset, endOfField, end, newGroupFields);

                if (position < 0)
                {
                    return position;
                }
            }
        }
    }

    return position;
}
 
Example #16
Source File: OtfParser.java    From artio with Apache License 2.0 4 votes vote down vote up
private boolean isEndOfGroup(final IntHashSet groupFields)
{
    return !groupFields.contains(tag);
}
 
Example #17
Source File: Generator.java    From artio with Apache License 2.0 4 votes vote down vote up
protected void generateImports(
    final String compoundSuffix,
    final AggregateType type,
    final Writer out,
    final Class<?>... extraImports) throws IOException
{
    out
        .append(importFor(MutableDirectBuffer.class))
        .append(importFor(AsciiSequenceView.class))
        .append(importStaticFor(CodecUtil.class))
        .append(importStaticFor(SessionConstants.class))
        .append(importFor(topType(MESSAGE)));

    if (topType(GROUP) != topType(MESSAGE))
    {
        out.append(importFor(topType(GROUP)));
    }

    out .append(type == MESSAGE ? String.format(COMMON_COMPOUND_IMPORTS, thisPackage, compoundSuffix) : "")
        .append(importFor(DecimalFloat.class))
        .append(importFor(MutableAsciiBuffer.class))
        .append(importFor(AsciiBuffer.class))
        .append(importFor(LocalMktDateEncoder.class))
        .append(importFor(UtcTimestampEncoder.class))
        .append(importFor(StandardCharsets.class))
        .append(importFor(Arrays.class))
        .append(importFor(CharArraySet.class))
        .append(importFor(IntHashSet.class))
        .append(importFor(IntHashSet.IntIterator.class))
        .append(importFor(EncodingException.class))
        .append(importFor(CharArrayWrapper.class));

    for (final Class<?> extraImport : extraImports)
    {
        out.append(importFor(extraImport));
    }

    out .append(importStaticFor(StandardCharsets.class, "US_ASCII"))
        .append(importStaticFor(validationClass, CODEC_VALIDATION_ENABLED))
        .append(importStaticFor(rejectUnknownFieldClass, CODEC_REJECT_UNKNOWN_FIELD_ENABLED))
        .append(importStaticFor(rejectUnknownEnumValueClass, RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY));

    if (!thisPackage.equals(commonPackage) && !commonPackage.isEmpty())
    {
        out.append(importFor(commonPackage + ".*"));
    }
}
 
Example #18
Source File: Message.java    From simple-binary-encoding with Apache License 2.0 4 votes vote down vote up
private List<Field> parseMembers(final Node node) throws XPathExpressionException
{
    final XPath xPath = XPathFactory.newInstance().newXPath();
    final NodeList list = (NodeList)xPath.compile(FIELD_OR_GROUP_OR_DATA_EXPR).evaluate(node, NODESET);
    boolean groupEncountered = false, dataEncountered = false;

    final ObjectHashSet<String> distinctNames = new ObjectHashSet<>();
    final IntHashSet distinctIds = new IntHashSet();
    final ArrayList<Field> fieldList = new ArrayList<>();

    for (int i = 0, size = list.getLength(); i < size; i++)
    {
        final Field field;
        final String nodeName = list.item(i).getNodeName();

        switch (nodeName)
        {
            case "group":
                if (dataEncountered)
                {
                    handleError(node, "group node specified after data node");
                }

                field = parseGroupField(list, i);
                groupEncountered = true;
                break;

            case "data":
                field = parseDataField(list, i);
                dataEncountered = true;
                break;

            case "field":
                if (groupEncountered || dataEncountered)
                {
                    handleError(node, "field node specified after group or data node specified");
                }

                field = parseField(list, i);
                break;

            default:
                throw new IllegalStateException("Unknown node name: " + nodeName);
        }

        if (!distinctIds.add(field.id()))
        {
            handleError(node, "duplicate id found: " + field.id());
        }

        if (!distinctNames.add(field.name()))
        {
            handleError(node, "duplicate name found: " + field.name());
        }

        fieldList.add(field);
    }

    return fieldList;
}