Recursively walk the spec input tree.  Handle arrays by telling DefaultrKeys if they need to be ArrayKeys, and
to find the max default array length.
342846
private static Set<Key> processSpec( boolean parentIsArray, Map<String, Object> spec ) {

        // TODO switch to List<Key> and sort before returning

        Set<Key> result = new HashSet<>();

        for ( String key : spec.keySet() ) {
            Object subSpec = spec.get( key );
            if ( parentIsArray ) {
                result.add( new ArrayKey( key, subSpec ) ); // this will recursively call processSpec if needed
            }
            else {
                result.add( new MapKey( key, subSpec ) ); // this will recursively call processSpec if needed
            }
        }

        return result;
    }
983773
private static void applyKeyToLiteralAndComputed( CardinalityCompositeSpec spec, String subKeyStr, Object subInput, WalkedPath walkedPath, Object input ) {

        CardinalitySpec literalChild = spec.literalChildren.get( subKeyStr );

        // if the subKeyStr found a literalChild, then we do not have to try to match any of the computed ones
        if ( literalChild != null ) {
            literalChild.applyCardinality( subKeyStr, subInput, walkedPath, input );
        } else {
            // If no literal spec key matched, iterate through all the computedChildren

            // Iterate through all the computedChildren until we find a match
            // This relies upon the computedChildren having already been sorted in priority order
            for ( CardinalitySpec computedChild : spec.computedChildren ) {
                // if the computed key does not match it will quickly return false
                if ( computedChild.applyCardinality( subKeyStr, subInput, walkedPath, input ) ) {
                    break;
                }
            }
        }
    }
1069897
def _siftdown_max(heap, startpos, pos):
    ''
    newitem = heap[pos]
    # Follow the path to the root, moving parents down until finding a place
    # newitem fits.
    while pos > startpos:
        parentpos = (pos - 1) >> 1
        parent = heap[parentpos]
        if parent < newitem:
            heap[pos] = parent
            pos = parentpos
            continue
        break
    heap[pos] = newitem
1253718
static boolean isNestedArrayPattern(Node n) {
    checkState(n.isArrayPattern());
    for (Node key = n.getFirstChild(); key != null; key = key.getNext()) {
      if (key.hasChildren()) {
        return true;
      }
    }
    return false;
  }
747623
def ensure_keys(walk, *keys):
    
    all_retrieved = True
    for k in keys:
        try:
            walk(k)
        except WalkKeyNotRetrieved:
            all_retrieved = False
    return all_retrieved
410537
public static function getChildByArray(array $keys, array $values, $default = null) {
		switch (count($keys)) {
			case 0:
				return $values;
			case 1:
				return array_key_exists($keys[0], $values) ? $values[$keys[0]] : $default;
			case 2:
				return isset($values[$keys[0]][$keys[1]]) ? $values[$keys[0]][$keys[1]] : $default;
			case 3:
				return isset($values[$keys[0]][$keys[1]][$keys[2]]) ? $values[$keys[0]][$keys[1]][$keys[2]] : $default;
			case 4:
				return isset($values[$keys[0]][$keys[1]][$keys[2]][$keys[3]]) ? $values[$keys[0]][$keys[1]][$keys[2]][$keys[3]] : $default;
			default:
				return isset($values[$keys[0]]) ? self::getChildByArray(array_slice($keys, 1), $values[$keys[0]], $default) : $default;
		}
	}
744790
def _check_default_index(items, default_index):
    ''''''
    num_items = len(items)
    if default_index is not None and not isinstance(default_index, int):
        raise TypeError("The default index ({}) is not an integer".format(default_index))
    if default_index is not None and default_index >= num_items:
        raise ValueError("The default index ({}) >= length of the list ({})".format(default_index, num_items))
    if default_index is not None and default_index < 0:
        raise ValueError("The default index ({}) < 0.".format(default_index))
    if default_index is not None and not items[default_index]:
        raise ValueError("The default index ({}) points to an empty item.".format(default_index))
847053
protected function & getFromArray(&$array, $keys, $default = null)
    {
        $key = array_shift($keys);
        if (!isset($array[$key])) {
            return $default;
        }

        if (empty($keys)) {
            return $array[$key];
        }

        return $this->getFromArray($array[$key], $keys, $default);
    }
1184568
def recursive_index_decode(int_array, max=32767, min=-32768):
    """"""
    out_arr = []
    encoded_ind = 0
    while encoded_ind < len(int_array):
        decoded_val = 0
        while int_array[encoded_ind]==max or int_array[encoded_ind]==min:
            decoded_val += int_array[encoded_ind]
            encoded_ind+=1
            if int_array[encoded_ind]==0:
                break
        decoded_val += int_array[encoded_ind]
        encoded_ind+=1
        out_arr.append(decoded_val)
    return out_arr
363195
protected static int[] newKeySizeArray(int minSize, int maxSize, int step)
    {
        int[] result = new int[((maxSize - minSize) / step) + 1];
        for (int i = minSize, j = 0; i <= maxSize; i += step, j++) {
            result[j] = i;
        }
        return result;
    }
374235
function _makeArrayChecker (defaultResult) {
    return function (arrayLike, predicate) {
        for (var i = 0, len = arrayLike.length; i < len; i++) {
            if (defaultResult ^ !!predicate(arrayLike[i], i, arrayLike)) {
                return !defaultResult;
            }
        }

        return defaultResult;
    };
}
1367110
public void handleInitialKey()                  // init this field override for other value
    {
        KeyArea keyArea = this.getKeyArea(-1);
        if (keyArea == null)
            return;
        BaseBuffer buffer = new VectorBuffer(null);
        boolean[] rgbModified = keyArea.getModified();
        boolean[] rgbNullable = keyArea.setNullable(true);
        keyArea.setupKeyBuffer(buffer, DBConstants.FILE_KEY_AREA);
        keyArea.zeroKeyFields(DBConstants.START_SELECT_KEY);        // Zero out the key fields
        BaseListener  nextListener = this.getNextEnabledListener();
        if (nextListener != null)
            ((FileListener)nextListener).doInitialKey();
        else
            this.doInitialKey();
        keyArea.setNullable(rgbNullable);
        keyArea.setModified(rgbModified);
        keyArea.reverseKeyBuffer(buffer, DBConstants.FILE_KEY_AREA);
    }
1100562
private void processChildren( List<RemovrSpec> children, Object subInput ) {

        if (subInput != null ) {

            if( subInput instanceof List ) {

                List<Object> subList = (List<Object>) subInput;
                Set<Integer> indiciesToRemove = new HashSet<>();

                // build a list of all indicies to remove
                for(RemovrSpec childSpec : children) {
                    indiciesToRemove.addAll( childSpec.applyToList( subList ) );
                }

                List<Integer> uniqueIndiciesToRemove = new ArrayList<>( indiciesToRemove );
                // Sort the list from Biggest to Smallest, so that when we remove items from the input
                //  list we don't muck up the order.
                // Aka removing 0 _then_ 3 would be bad, because we would have actually removed
                //  0 and 4 from the "original" list.
                Collections.sort( uniqueIndiciesToRemove, new Comparator<Integer>() {
                    @Override
                    public int compare( Integer o1, Integer o2 ) {
                        return o2.compareTo( o1 );
                    }
                } );

                for ( int index : uniqueIndiciesToRemove ) {
                    subList.remove( index );
                }
            }
            else if (subInput instanceof Map ) {

                Map<String,Object> subInputMap = (Map<String,Object>) subInput;

                List<String> keysToRemove = new LinkedList<>();

                for(RemovrSpec childSpec : children) {
                    keysToRemove.addAll( childSpec.applyToMap( subInputMap ) );
                }

                subInputMap.keySet().removeAll( keysToRemove );
            }
        }
    }
507878
private void ensureCapacity() {
		if (size < selectionKeys.length) {
			return;
		}
		SelectionKey[] newArray = new SelectionKey[selectionKeys.length * 2];
		System.arraycopy(selectionKeys, 0, newArray, 0, size);
		selectionKeys = newArray;
	}
888471
private void ensureEntryArrayMutable() {
    checkMutable();
    if (entryList.isEmpty() && !(entryList instanceof ArrayList)) {
      entryList = new ArrayList<Entry>(maxArraySize);
    }
  }
973219
private function getIn(array $array, array $keys, $default = null)
    {
        if (!$keys) {
            return $array;
        }

        // This is a micro-optimization, it is fast for non-nested keys, but fails for null values
        if (\count($keys) === 1 && isset($array[$keys[0]])) {
            return $array[$keys[0]];
        }

        $current = $array;
        foreach ($keys as $key) {
            if (!\is_array($current) || !\array_key_exists($key, $current)) {
                return $default;
            }

            $current = $current[$key];
        }

        return $current;
    }
343033
private static void expandAllRecursively(JTree tree, TreePath treePath)
    {
        TreeModel model = tree.getModel();
        Object lastPathComponent = treePath.getLastPathComponent();
        int childCount = model.getChildCount(lastPathComponent);
        if (childCount == 0)
        {
            return;
        }
        tree.expandPath(treePath);
        for (int i=0; i<childCount; i++)
        {
            Object child = model.getChild(lastPathComponent, i);
            int grandChildCount = model.getChildCount(child);
            if (grandChildCount > 0)
            {
                class LocalTreePath extends TreePath
                {
                    private static final long serialVersionUID = 0;
                    public LocalTreePath(
                        TreePath parent, Object lastPathComponent)
                    {
                        super(parent, lastPathComponent);
                    }
                }
                TreePath nextTreePath = new LocalTreePath(treePath, child);
                expandAllRecursively(tree, nextTreePath);
            }
        }
    }