Creates the position.

@param position the position
@param encode the encode
@return the simple ordered map
@throws IOException Signals that an I/O exception has occurred.
180713
private SimpleOrderedMap<Object> createPosition(ComponentPosition position,
      Boolean encode) throws IOException {
    // System.out.println("Create stats position " + position.dataType + " "
    // + position.statsType + " " + position.statsItems + " --- " + encode);
    SimpleOrderedMap<Object> mtasPositionResponse = new SimpleOrderedMap<>();
    mtasPositionResponse.add("key", position.key);
    MtasSolrMtasResult data = new MtasSolrMtasResult(position.dataCollector,
        position.dataType, position.statsType, position.statsItems, null, null);
    if (encode) {
      mtasPositionResponse.add("_encoded_data",
          MtasSolrResultUtil.encode(data));
    } else {
      mtasPositionResponse.add(position.dataCollector.getCollectorType(), data);
      MtasSolrResultUtil.rewrite(mtasPositionResponse, searchComponent);
    }
    return mtasPositionResponse;
  }
1076781
static Positions newDisjointPositions(Matches matches, int position) {
		if (matches == null) throw new IllegalArgumentException("null matches");
		if (position < 0L) throw new IllegalArgumentException();
		//TODO consider restoring dedicated size accessor on matches
		if (position > matches.store().size()) throw new IllegalArgumentException();
		int p = matches.first();
		int s = matches.sequence().size();
		while (p < position) {
			p = matches.next(p + s);
		}
		return new BitStorePositions(matches, true, p);
	}
1251662
int mapPosition(int position) {
		int out = position;
		for (int delta : positionDeltas.headMap(position, true).values()) {
			out += delta;
		}
		return out;
	}
1179925
int assignPosition(Id id) throws RepositoryException {

        int pos = -1;
        if (!freePositions.isEmpty()) {
            pos = freePositions.remove(0);
        } else {
            pos = nextPos++;
            ensureCapacity(pos);
        }

        idPosMap.put(id, pos);

        for (HierarchicalTypeStore s : superTypeStores) {
            s.assignPosition(id);
        }

        return pos;
    }
192487
public static <T> ImmutableCheck<T> of(Position.Readable<T> position) {
        return new ImmutableCheck<>(position);
    }
190703
public SimpleOrderedMap<Object> create(ComponentList list, Boolean encode) {
    SimpleOrderedMap<Object> mtasListResponse = new SimpleOrderedMap<>();
    mtasListResponse.add("key", list.key);
    if (list.number == 0) {
      mtasListResponse.add("total", list.total);
    }
    if (list.output != null) {
      ArrayList<NamedList<Object>> mtasListItemResponses = new ArrayList<>();
      if (list.output.equals(ComponentList.LIST_OUTPUT_HIT)) {
        mtasListResponse.add("number", list.hits.size());
        for (ListHit hit : list.hits) {
          NamedList<Object> mtasListItemResponse = new SimpleOrderedMap<>();
          mtasListItemResponse.add("documentKey",
              list.uniqueKey.get(hit.docId));
          mtasListItemResponse.add("documentHitPosition", hit.docPosition);
          mtasListItemResponse.add("documentHitTotal",
              list.subTotal.get(hit.docId));
          mtasListItemResponse.add("documentMinPosition",
              list.minPosition.get(hit.docId));
          mtasListItemResponse.add("documentMaxPosition",
              list.maxPosition.get(hit.docId));
          mtasListItemResponse.add("startPosition", hit.startPosition);
          mtasListItemResponse.add("endPosition", hit.endPosition);

          SortedMap<Integer, List<List<String>>> hitData = new TreeMap<>();
          SortedMap<Integer, List<List<String>>> leftData = null;
          SortedMap<Integer, List<List<String>>> rightData = null;
          if (list.left > 0) {
            leftData = new TreeMap<>();
          }
          if (list.right > 0) {
            rightData = new TreeMap<>();
          }
          for (int position = Math.max(0,
              hit.startPosition - list.left); position <= (hit.endPosition
                  + list.right); position++) {
            List<List<String>> hitDataItem = new ArrayList<>();
            if (hit.hits.containsKey(position)) {
              for (String term : hit.hits.get(position)) {
                List<String> hitDataSubItem = new ArrayList<>();
                hitDataSubItem.add(CodecUtil.termPrefix(term));
                hitDataSubItem.add(CodecUtil.termValue(term));
                hitDataItem.add(hitDataSubItem);
              }
            }
            if (position < hit.startPosition) {
              if (leftData != null) {
                leftData.put(position, hitDataItem);
              }
            } else if (position > hit.endPosition) {
              if (rightData != null) {
                rightData.put(position, hitDataItem);
              }
            } else {
              hitData.put(position, hitDataItem);
            }
          }
          if (list.left > 0) {
            mtasListItemResponse.add("left", leftData);
          }
          mtasListItemResponse.add("hit", hitData);
          if (list.right > 0) {
            mtasListItemResponse.add("right", rightData);
          }
          mtasListItemResponses.add(mtasListItemResponse);
        }
      } else if (list.output.equals(ComponentList.LIST_OUTPUT_TOKEN)) {
        mtasListResponse.add("number", list.tokens.size());
        for (ListToken tokenHit : list.tokens) {
          NamedList<Object> mtasListItemResponse = new SimpleOrderedMap<>();
          mtasListItemResponse.add("documentKey",
              list.uniqueKey.get(tokenHit.docId));
          mtasListItemResponse.add("documentHitPosition", tokenHit.docPosition);
          mtasListItemResponse.add("documentHitTotal",
              list.subTotal.get(tokenHit.docId));
          mtasListItemResponse.add("documentMinPosition",
              list.minPosition.get(tokenHit.docId));
          mtasListItemResponse.add("documentMaxPosition",
              list.maxPosition.get(tokenHit.docId));
          mtasListItemResponse.add("startPosition", tokenHit.startPosition);
          mtasListItemResponse.add("endPosition", tokenHit.endPosition);

          ArrayList<NamedList<Object>> mtasListItemResponseItemTokens = new ArrayList<>();
          for (MtasToken token : tokenHit.tokens) {
            NamedList<Object> mtasListItemResponseItemToken = new SimpleOrderedMap<>();
            if (token.getId() != null) {
              mtasListItemResponseItemToken.add("mtasId", token.getId());
            }
            mtasListItemResponseItemToken.add("prefix", token.getPrefix());
            mtasListItemResponseItemToken.add("value", token.getPostfix());
            if (token.getPositionStart() != null) {
              mtasListItemResponseItemToken.add("positionStart",
                  token.getPositionStart());
              mtasListItemResponseItemToken.add("positionEnd",
                  token.getPositionEnd());
            }
            if (token.getPositions() != null) {
              mtasListItemResponseItemToken.add("positions",
                  Arrays.toString(token.getPositions()));
            }
            if (token.getParentId() != null) {
              mtasListItemResponseItemToken.add("parentMtasId",
                  token.getParentId());
            }
            if (token.getPayload() != null) {
              mtasListItemResponseItemToken.add("payload", token.getPayload());
            }
            if (token.getOffsetStart() != null) {
              mtasListItemResponseItemToken.add("offsetStart",
                  token.getOffsetStart());
              mtasListItemResponseItemToken.add("offsetEnd",
                  token.getOffsetEnd());
            }
            if (token.getRealOffsetStart() != null) {
              mtasListItemResponseItemToken.add("realOffsetStart",
                  token.getRealOffsetStart());
              mtasListItemResponseItemToken.add("realOffsetEnd",
                  token.getRealOffsetEnd());
            }
            mtasListItemResponseItemTokens.add(mtasListItemResponseItemToken);
          }
          mtasListItemResponse.add("tokens", mtasListItemResponseItemTokens);
          mtasListItemResponses.add(mtasListItemResponse);
        }
      }
      mtasListResponse.add(NAME, mtasListItemResponses);
    }
    return mtasListResponse;
  }
1364194
@SuppressWarnings("unchecked")
  public SimpleOrderedMap<Object> create(ComponentGroup group, Boolean encode)
      throws IOException {
    SimpleOrderedMap<Object> mtasGroupResponse = new SimpleOrderedMap<>();
    mtasGroupResponse.add("key", group.key);
    MtasSolrMtasResult data = new MtasSolrMtasResult(group.dataCollector,
        new String[] { group.dataType }, new String[] { group.statsType },
        new SortedSet[] { group.statsItems }, new List[] { null },
        new String[] { group.sortType }, new String[] { group.sortDirection },
        new Integer[] { group.start }, new Integer[] { group.number }, null);
    if (encode) {
      mtasGroupResponse.add("_encoded_list", MtasSolrResultUtil.encode(data));
    } else {
      mtasGroupResponse.add("list", data);
      MtasSolrResultUtil.rewrite(mtasGroupResponse, searchComponent);
    }
    return mtasGroupResponse;
  }
372739
public void writeByteCurrentPosition(byte v) throws IOException {
    int index = (int)(position - bufferOffset);
    if (index < maxBufferSize) {
      buffer[index] = v;
      isByte[index] = true;
      if (index + 1 > currentBufferSize) currentBufferSize = index + 1;
      if (index + 1 >= maxBufferSize) {
        writeBuffer();
        newBuffer(position + 1);
      }
    } else {
      aFile.write(v);
    }
    position++;
  }
1159317
public void setPosition(int position) {

        switch (position) {
            case Simapi.POS_DOWN_LEFT:
            case Simapi.POS_DOWN_RIGHT:
            case Simapi.POS_STRAIGHT_DOWN:
            case Simapi.POS_STRAIGHT_LEFT:
            case Simapi.POS_STRAIGHT_RIGHT:
            case Simapi.POS_STRAIGHT_UP:
            case Simapi.POS_UP_LEFT:
            case Simapi.POS_UP_RIGHT:
                // position is fine
                m_position = position;
                break;
            default:
                m_position = Simapi.POS_CENTER;
        }
    }
1269460
public SimpleOrderedMap<Object> create(ComponentDocument document,
      Boolean encode) throws IOException {
    SimpleOrderedMap<Object> mtasDocumentResponse = new SimpleOrderedMap<>();
    mtasDocumentResponse.add("key", document.key);
    ArrayList<NamedList<Object>> mtasDocumentItemResponses = new ArrayList<>();
    for (int docId : document.statsData.keySet()) {
      NamedList<Object> mtasDocumentItemResponse = new SimpleOrderedMap<>();
      MtasDataCollector<?, ?> stats = document.statsData.get(docId);
      MtasDataCollector<?, ?> list = null;
      if (document.statsList != null) {
        list = document.statsList.get(docId);
      }
      mtasDocumentItemResponse.add("stats",
          new MtasSolrMtasResult(stats, stats.getDataType(),
              stats.getStatsType(), stats.getStatsItems(), null, null));
      mtasDocumentItemResponse.add("documentKey",
          document.uniqueKey.get(docId));
      if (list != null) {
        if (document.listExpand) {
          mtasDocumentItemResponse.add("list",
              new MtasSolrMtasResult(list,
                  new String[] { list.getDataType(), list.getDataType() },
                  new String[] { list.getStatsType(), list.getStatsType() },
                  new SortedSet[] { list.getStatsItems(),
                      list.getStatsItems() },
                  new List[] { null, null }, new String[] { null, null },
                  new String[] { null, null }, new Integer[] { 0, 0 },
                  new Integer[] { 1, 1 }, null));
        } else {
          mtasDocumentItemResponse.add("list",
              new MtasSolrMtasResult(list, list.getDataType(),
                  list.getStatsType(), list.getStatsItems(), null, null));
        }

      }
      // add
      mtasDocumentItemResponses.add(mtasDocumentItemResponse);
    }
    mtasDocumentResponse.add("list", mtasDocumentItemResponses);
    MtasSolrResultUtil.rewrite(mtasDocumentResponse, searchComponent);
    return mtasDocumentResponse;
  }
344906
public synchronized void seek(long position) throws IOException {
    if (position < 0 || position >= count) {
      throw new IOException("cannot seek position " + position + " as it is out of bounds");
    }
    pos = (int) position;
  }
1115063
def encode_positions(self,
                         positions: mx.sym.Symbol,
                         data: mx.sym.Symbol) -> mx.sym.Symbol:
        

        # (batch_size, source_seq_len, num_embed)
        pos_embedding = mx.sym.Embedding(data=positions,
                                         input_dim=self.max_seq_len,
                                         weight=self.embed_weight,
                                         output_dim=self.num_embed,
                                         name=self.prefix + "pos_embed")
        return mx.sym.broadcast_add(data, pos_embedding, name="%s_add" % self.prefix)
816828
public int getNodeByPosition(int position)
  {
    if (position > 0) {
      final int pos = isReverse() ? getLast() - position + 1
                                   : position;
      int node;
      while ((node = next()) != DTMAxisIterator.END) {
        if (pos == getPosition()) {
          return node;
        }
      }
    }
    return END;
  }
1161568
public EntryPosition getPosition(Object key, byte[] serializedKey) throws IOException {
      int segment = (key.hashCode() & Integer.MAX_VALUE) % segments.length;
      lock.readLock().lock();
      try {
         return IndexNode.applyOnLeaf(segments[segment], serializedKey, segments[segment].rootReadLock(), IndexNode.ReadOperation.GET_POSITION);
      } finally {
         lock.readLock().unlock();
      }
   }
320678
private static PortablePosition createPositionForReadAccess(
            PortableNavigatorContext ctx, PortablePathCursor path) throws IOException {
        int notArrayCellAccessIndex = -1;
        return createPositionForReadAccess(ctx, path, notArrayCellAccessIndex);
    }
551792
public IVarDef.Position getPosition()
    {
    if( position_ == null)
      {
      setPosition( new Position( getParent(), seqNum_));
      }
    
    return position_;
    }
93372
public SimpleOrderedMap<Object> create(ComponentFacet facet, Boolean encode)
      throws IOException {
    SimpleOrderedMap<Object> mtasFacetResponse = new SimpleOrderedMap<>();
    mtasFacetResponse.add("key", facet.key);
    HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<>();
    for (int i = 0; i < facet.baseFields.length; i++) {
      if (facet.baseFunctionList[i] != null) {
        for (MtasDataCollector<?, ?> functionDataCollector : facet.baseFunctionList[i]
            .keySet()) {
          SubComponentFunction[] tmpSubComponentFunctionList = facet.baseFunctionList[i]
              .get(functionDataCollector);
          if (tmpSubComponentFunctionList != null) {
            HashMap<String, MtasSolrMtasResult> tmpList = new HashMap<>();
            for (SubComponentFunction tmpSubComponentFunction : tmpSubComponentFunctionList) {
              tmpList.put(tmpSubComponentFunction.key,
                  new MtasSolrMtasResult(tmpSubComponentFunction.dataCollector,
                      tmpSubComponentFunction.dataType,
                      tmpSubComponentFunction.statsType,
                      tmpSubComponentFunction.statsItems, null, null));
            }
            functionData.put(functionDataCollector, tmpList);
          }
        }
      }
    }
    MtasSolrMtasResult data = new MtasSolrMtasResult(facet.dataCollector,
        facet.baseDataTypes, facet.baseStatsTypes, facet.baseStatsItems, null,
        facet.baseSortTypes, facet.baseSortDirections, null, facet.baseNumbers,
        functionData);

    if (encode) {
      mtasFacetResponse.add("_encoded_list", MtasSolrResultUtil.encode(data));
    } else {
      mtasFacetResponse.add("list", data);
      MtasSolrResultUtil.rewrite(mtasFacetResponse, searchComponent);
    }
    return mtasFacetResponse;
  }