<commit_before>/*
 * Copyright © 2017 <<EMAIL>> http://io7m.com
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

package com.io7m.smfj.bytebuffer;

import com.io7m.jaffirm.core.Preconditions;
import com.io7m.smfj.core.SMFAttribute;
import com.io7m.smfj.core.SMFAttributeName;
import com.io7m.smfj.core.SMFImmutableStyleType;
import javaslang.Tuple;
import javaslang.collection.HashMap;
import javaslang.collection.Seq;
import javaslang.collection.SortedMap;
import javaslang.collection.TreeMap;
import org.immutables.value.Value;

/**
 * The byte buffer packing configuration.
 */

@SMFImmutableStyleType
@Value.Immutable
public interface SMFByteBufferPackingConfigurationType
{
  /**
   * A specification of the sequence of attributes that will be packed into the
   * byte buffer. For each vertex in turn, the value of each attribute will be
   * packed (interleaved) into the buffer in the order given by this sequence.
   *
   * @return The sequence of attributes that will be packed into the byte buffer
   */

  @Value.Parameter
  Seq<SMFAttribute> attributesOrdered();

  /**
   * @return The packed attributes by octet offset
   */

  @Value.Derived
  default SortedMap<Integer, SMFByteBufferPackedAttribute> packedAttributesByOffset()
  {
    TreeMap<Integer, SMFByteBufferPackedAttribute> output = TreeMap.empty();
    final Seq<SMFAttribute> ordered = this.attributesOrdered();
    int offset = 0;
    for (int index = 0; index < ordered.size(); ++index) {
      final SMFAttribute attr = ordered.get(index);
      final SMFByteBufferPackedAttribute packed =
        SMFByteBufferPackedAttribute.of(attr, index, offset);
      output = output.put(Integer.valueOf(offset), packed);
      offset = Math.addExact(offset, attr.sizeOctets());
    }<commit_msg>Enable javaslang encodings fro byte buffer packing configuration<commit_after>/*
 * Copyright © 2017 <<EMAIL>> http://io7m.com
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

package com.io7m.smfj.bytebuffer;

import com.io7m.jaffirm.core.Preconditions;
import com.io7m.smfj.core.SMFAttribute;
import com.io7m.smfj.core.SMFAttributeName;
import com.io7m.smfj.core.SMFImmutableStyleType;
import javaslang.Tuple;
import javaslang.collection.HashMap;
import javaslang.collection.Seq;
import javaslang.collection.SortedMap;
import javaslang.collection.TreeMap;
import org.immutables.javaslang.encodings.JavaslangEncodingEnabled;
import org.immutables.value.Value;

/**
 * The byte buffer packing configuration.
 */

@SMFImmutableStyleType
@JavaslangEncodingEnabled
@Value.Immutable
public interface SMFByteBufferPackingConfigurationType
{
  /**
   * A specification of the sequence of attributes that will be packed into the
   * byte buffer. For each vertex in turn, the value of each attribute will be
   * packed (interleaved) into the buffer in the order given by this sequence.
   *
   * @return The sequence of attributes that will be packed into the byte buffer
   */

  @Value.Parameter
  Seq<SMFAttribute> attributesOrdered();

  /**
   * @return The packed attributes by octet offset
   */

  @Value.Derived
  default SortedMap<Integer, SMFByteBufferPackedAttribute> packedAttributesByOffset()
  {
    TreeMap<Integer, SMFByteBufferPackedAttribute> output = TreeMap.empty();
    final Seq<SMFAttribute> ordered = this.attributesOrdered();
    int offset = 0;
    for (int index = 0; index < ordered.size(); ++index) {
      final SMFAttribute attr = ordered.get(index);
      final SMFByteBufferPackedAttribute packed =
        SMFByteBufferPackedAttribute.of(attr, index, offset);
      output = output.put(Integer.valueOf(offset), packed);
      offset = Math.addExact(offset, attr.sizeOctets());
    }
{'fraction_non_alphanumeric': 0.07916089451810805, 'fraction_numerical': 0.004749653671086484, 'mean_word_length': 4.370882040382572, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '539729', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1415, 'n_words': 510}