todo/check: adm1 => state
   why use adm1 and not state ??  duplicate of match___country_n_state ??
3975
def match_xxx_for_country_n_adm1( name, xxx ) # xxx e.g. parts|counties|etc.

    # auto-add required country n states (from folder structure)
    #
    #  e.g.  de-deutschland!/3--by-bayern/parts  (regierungsbezirke)
    #        europe/de-deutschland!/3--by-bayern/parts
    #
    #    at-austria!/1--n-niederoesterreich/counties  (bezirke)

    xxx_pattern           = "#{xxx}"

    if name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_STATE_MODERN_PATTERN}\/#{xxx_pattern}/  ||
       name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_STATE_CLASSIC_PATTERN}\/#{xxx_pattern}/

      country_key = $1.dup
      state_key  = $2.dup
      yield( country_key, state_key )
      true # bingo - match found
    else
      false # no match found
    end
  end
1106268
def sameState (s1, s2):
    
    if (len(s1[1]) != len(s2[1])) or (s1[2] != s2[2]):
        return False
    for arcIndex in range(0, len(s1[1])):
        arc1 = s1[1][arcIndex]
        arc2 = s2[1][arcIndex]
        if arc1[:-1] != arc2[:-1]:
            return False
    return True
302094
function howMuchToRead(n, state) {
  if (n <= 0 || state.length === 0 && state.ended) return 0;
  if (state.objectMode) return 1;
  if (n !== n) {
    // Only flow one buffer at a time
    if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  }
  // If we're asking for more than the current hwm, then raise the hwm.
  if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  if (n <= state.length) return n;
  // Don't have enough
  if (!state.ended) {
    state.needReadable = true;
    return 0;
  }
  return state.length;
}
896561
def notGroup (states, *stateIndexPairs):
    
    start, dead = group(states, *stateIndexPairs)
    finish = len(states)
    states.append([])
    states[start].append((DEFAULT, finish))
    return start, finish
380602
@Override
    public final long computeNorm(FieldInvertState state) {

        final int numTerms = m_bm25Sim.getDiscountOverlaps()
        ? state.getLength() - state.getNumOverlap()
        : state.getLength();

        if (state.getIndexCreatedVersionMajor() >= 7) {
            return SmallFloat.intToByte4(numTerms);
        } else {
            return SmallFloat.floatToByte315(lengthNorm(state, numTerms));
        }
    }
894664
private static boolean matchNaN(byte[] str, byte firstchar, int start, int end) {
    final int len = end - start;
    if(len < 2 || len > 3 || (firstchar != 'N' && firstchar != 'n')) {
      return false;
    }
    final byte c1 = str[start + 1];
    if(c1 != 'a' && c1 != 'A') {
      return false;
    }
    // Accept just "NA", too:
    if(len == 2) {
      return true;
    }
    final byte c2 = str[start + 2];
    return c2 == 'N' || c2 == 'n';
  }
609727
def match_country( value )
    if value =~ /^country:/       # country:
      country_key = value[8..-1]  # cut off country: prefix
      country = WorldDb::Model::Country.find_by_key!( country_key )
      yield( country )
      true # bingo - match found
    else
      false # no match found
    end
  end
198350
def match_state_for_country( value, country_id )  ## NB: required country_id 
    if value =~ /^state:/   ## state:
      state_key = value[6..-1]  ## cut off state: prefix
      state = WorldDb::Model::State.find_by_key_and_country_id!( state_key, country_id )
      yield( state )
      true  # bingo - match found
    elsif is_state?( value )  ## assume state code e.g. TX or N
      state = WorldDb::Model::State.find_by_key_and_country_id!( value.downcase, country_id )
      yield( state )
      true  # bingo - match found
    else
      false # no match found
    end
  end
835771
public final void mAS() throws RecognitionException {
		try {
			int _type = AS;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// druidG.g:626:5: ( ( 'AS' | 'as' ) )
			// druidG.g:626:7: ( 'AS' | 'as' )
			{
			// druidG.g:626:7: ( 'AS' | 'as' )
			int alt15=2;
			int LA15_0 = input.LA(1);
			if ( (LA15_0=='A') ) {
				alt15=1;
			}
			else if ( (LA15_0=='a') ) {
				alt15=2;
			}

			else {
				NoViableAltException nvae =
					new NoViableAltException("", 15, 0, input);
				throw nvae;
			}

			switch (alt15) {
				case 1 :
					// druidG.g:626:8: 'AS'
					{
					match("AS"); 

					}
					break;
				case 2 :
					// druidG.g:626:13: 'as'
					{
					match("as"); 

					}
					break;

			}

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
229421
private State checkA(State state) throws DatatypeException, IOException {
        if (state.context.length() == 0) {
            state = appendToContext(state);
        }
        state.current = state.reader.read();
        state = appendToContext(state);
        state = skipSpaces(state);
        boolean expectNumber = true;

        for (;;) {
            switch (state.current) {
                default:
                    if (expectNumber)
                        reportNonNumber('A', state.current, state.context);
                    return state;

                case '+':
                case '-':
                case '.':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    break;
            }

            state = checkArg('A', "rx radius", state);
            state = skipCommaSpaces(state);
            state = checkArg('A', "ry radius", state);
            state = skipCommaSpaces(state);
            state = checkArg('A', "x-axis-rotation", state);
            state = skipCommaSpaces(state);

            switch (state.current) {
                default:
                    reportUnexpected("\u201c0\u201d or \u201c1\u201d for"
                            + " large-arc-flag for \u201cA\u201d" + " command",
                            state.current, state.context);
                    state = skipSubPath(state);
                    return state;
                case '0':
                case '1':
                    break;
            }

            state.current = state.reader.read();
            state = appendToContext(state);
            state = skipCommaSpaces(state);

            switch (state.current) {
                default:
                    reportUnexpected("\u201c0\u201d or \u201c1\u201d for"
                            + " sweep-flag for \u201cA\u201d" + " command",
                            state.current, state.context);
                    state = skipSubPath(state);
                    return state;
                case '0':
                case '1':
                    break;
            }

            state.current = state.reader.read();
            state = appendToContext(state);
            state = skipCommaSpaces(state);

            state = checkArg('A', "x coordinate", state);
            state = skipCommaSpaces(state);
            state = checkArg('A', "y coordinate", state);

            state = skipCommaSpaces2(state);
            expectNumber = state.skipped;
        }
    }
100155
private void repartitionSplitState(
			Map<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> nameToDistributeState,
			int newParallelism,
			List<Map<StreamStateHandle, OperatorStateHandle>> mergeMapList) {

		int startParallelOp = 0;
		// Iterate all named states and repartition one named state at a time per iteration
		for (Map.Entry<String, List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>>> e :
				nameToDistributeState.entrySet()) {

			List<Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo>> current = e.getValue();

			// Determine actual number of partitions for this named state
			int totalPartitions = 0;
			for (Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo> offsets : current) {
				totalPartitions += offsets.f1.getOffsets().length;
			}

			// Repartition the state across the parallel operator instances
			int lstIdx = 0;
			int offsetIdx = 0;
			int baseFraction = totalPartitions / newParallelism;
			int remainder = totalPartitions % newParallelism;

			int newStartParallelOp = startParallelOp;

			for (int i = 0; i < newParallelism; ++i) {

				// Preparation: calculate the actual index considering wrap around
				int parallelOpIdx = (i + startParallelOp) % newParallelism;

				// Now calculate the number of partitions we will assign to the parallel instance in this round ...
				int numberOfPartitionsToAssign = baseFraction;

				// ... and distribute odd partitions while we still have some, one at a time
				if (remainder > 0) {
					++numberOfPartitionsToAssign;
					--remainder;
				} else if (remainder == 0) {
					// We are out of odd partitions now and begin our next redistribution round with the current
					// parallel operator to ensure fair load balance
					newStartParallelOp = parallelOpIdx;
					--remainder;
				}

				// Now start collection the partitions for the parallel instance into this list

				while (numberOfPartitionsToAssign > 0) {
					Tuple2<StreamStateHandle, OperatorStateHandle.StateMetaInfo> handleWithOffsets =
							current.get(lstIdx);

					long[] offsets = handleWithOffsets.f1.getOffsets();
					int remaining = offsets.length - offsetIdx;
					// Repartition offsets
					long[] offs;
					if (remaining > numberOfPartitionsToAssign) {
						offs = Arrays.copyOfRange(offsets, offsetIdx, offsetIdx + numberOfPartitionsToAssign);
						offsetIdx += numberOfPartitionsToAssign;
					} else {
						if (OPTIMIZE_MEMORY_USE) {
							handleWithOffsets.f1 = null; // GC
						}
						offs = Arrays.copyOfRange(offsets, offsetIdx, offsets.length);
						offsetIdx = 0;
						++lstIdx;
					}

					numberOfPartitionsToAssign -= remaining;

					// As a last step we merge partitions that use the same StreamStateHandle in a single
					// OperatorStateHandle
					Map<StreamStateHandle, OperatorStateHandle> mergeMap = mergeMapList.get(parallelOpIdx);
					OperatorStateHandle operatorStateHandle = mergeMap.get(handleWithOffsets.f0);
					if (operatorStateHandle == null) {
						operatorStateHandle = new OperatorStreamStateHandle(
							new HashMap<>(nameToDistributeState.size()),
							handleWithOffsets.f0);
						mergeMap.put(handleWithOffsets.f0, operatorStateHandle);
					}
					operatorStateHandle.getStateNameToPartitionOffsets().put(
							e.getKey(),
							new OperatorStateHandle.StateMetaInfo(offs, OperatorStateHandle.Mode.SPLIT_DISTRIBUTE));
				}
			}
			startParallelOp = newStartParallelOp;
			e.setValue(null);
		}
	}
738071
public static void checkState(boolean b, String msg, long arg1, long arg2, long arg3, long arg4) {
        if (!b) {
            throwStateEx(msg, arg1, arg2, arg3, arg4);
        }
    }
685949
private State checkl(State state) throws DatatypeException, IOException {
        if (state.context.length() == 0) {
            state = appendToContext(state);
        }
        state.current = state.reader.read();
        state = appendToContext(state);
        state = skipSpaces(state);
        _checkl('l', true, state);
        return state;
    }
34483
function(state,statePointer,nbr,isInv)
		{
			for (var i = 0; i < nbr; i++)
			{
				if(isInv)
				{
					var tmp = state[statePointer + 3];
					for (var j = 3; j > 0; j--)
						state[statePointer + j] = state[statePointer + j-1];
					state[statePointer] = tmp;
				}
				else
				{
					var tmp = state[statePointer];
					for (var j = 0; j < 3; j++)
						state[statePointer + j] = state[statePointer + j+1];
					state[statePointer + 3] = tmp;
				}
			}
			return state;
		}
1369763
def state
      result = @provider.state
      raise Errors::MachineStateInvalid if !result.is_a?(MachineState)

      # Update our state cache if we have a UUID and an entry in the
      # master index.
      uuid = index_uuid
      if uuid
        # active_machines provides access to query this info on each machine
        # from a different thread, ensure multiple machines do not access
        # the locked entry simultaneously as this triggers a locked machine
        # exception.
        @state_mutex.synchronize do
          entry = @env.machine_index.get(uuid)
          if entry
            entry.state = result.short_description
            @env.machine_index.set(entry)
            @env.machine_index.release(entry)
          end
        end
      end

      result
    end
571660
private Environment checkAssign(Stmt.Assign stmt, Environment environment, EnclosingScope scope)
			throws IOException {
		Tuple<LVal> lvals = stmt.getLeftHandSide();
		Type[] types = new Type[lvals.size()];
		for (int i = 0; i != lvals.size(); ++i) {
			types[i] = checkLVal(lvals.get(i), environment);
		}
		checkMultiExpressions(stmt.getRightHandSide(), environment, new Tuple<>(types));
		return environment;
	}
1246259
@Override
    public boolean isSameState(Word<I> input1, S s1, Word<I> input2, S s2) {
        return s1.equals(s2);
    }