Inserts the provided element in the right order given the priority

The lowest priority will be the first element in the list. If no priority
if given, the

@param mixed $element
@param int  $priority

@return PriorityList
347278
public function insert($element, $priority = 0)
    {
        $data = [];
        $inserted = false;
        $priority = $priority === 0 ? $this->lastPriority : $priority;

        foreach ($this->data as $datum) {
            $inserted = $this->tryToInsert($element, $priority, $data, $datum);
            $data[] = ['element' => $datum['element'], 'priority' => $datum['priority']];
            $this->lastPriority = $datum['priority'];
        }

        if (!$inserted) {
            $data[] = ['element' => $element, 'priority' => $priority];
            $this->lastPriority = $priority;
        }

        $this->data = $data;
        return $this;
    }
1298192
public function add($element) {
        $currentValue = $this->getRawValue();

        if (!in_array($element, $currentValue)) {
            $currentValue[] = $element;
            $this->setRawValue($currentValue);
        }

        return $this;
    }
471282
protected function reparentElement(DOMElement $element)
	{
		$parentNode = $element->parentNode;
		do
		{
			$lastChild = $parentNode->lastChild;
			$parentNode->parentNode->insertBefore($lastChild, $parentNode->nextSibling);
		}
		while (!$lastChild->isSameNode($element));
	}
1216997
public static function add( $element, $location = [] ) {
		if ( ! isset( self::$_elements[ $element ] ) ) {
			self::$_elements[ $element ] = [];
		}

		if ( empty( $location ) ) {
			$default_location = self::get_default_location( $element );

			if ( $default_location ) {
				self::$_elements[ $element ][] = [ $default_location ];
			} else {
				throw new \Exception( 'Element ' . $element . ' does not have a default location. You must supply the $location parameter.' );
			}
		} else {
			self::$_elements[ $element ][] = [ $location ];
		}

		add_action( 'init', [ __CLASS__, 'register_elements' ] );
	}
167157
public function pushScalar(array $element) {
        if(!empty($element['required'])) {
            $this->hasRequired = true;
        }
        if(empty($this->containers)) {
            $this->array += $element;
        } else {
            $this->containers[count($this->containers) - 1][\Illuminate\Support\Arr::get($element, 'id')] = $element;
        }
    }
1150063
public function setPriority($priority)
    {
        if (! (is_float($priority) && $priority >= 0 && $priority <= 1)) {
            throw new Exception('Priority must be >=0.0 and <=1.0');
        }

        $this->priority = number_format($priority, 1);

        return $this;
    }
182737
public function pushScalar(array $element)
    {
        if (!empty($element['required'])) {
            $this->hasRequired = true;
        }
        if (empty($this->containers)) {
            $this->array += $element;
        } else {
            $this->containers[count($this->containers) - 1][] = $element;
        }
    }
155637
public function addElement(OrderElement $elements)
    {
        $this->elements[] = $elements;
        $elements->setOrder($this);

        return $this;
    }
1170428
public function add(PriorityQueueItem $item) {
        $priority = $item->getPriority();
        if (!isset($this->items[$priority])) {
            $this->items[$priority] = array($item);
        } else {
            $this->items[$priority][] = $item;
        }
        return $this;
    }
674531
public function insert($data, $priority = 0)
    {
        $this->data[] = [
            'data'     => $data,
            'priority' => $priority,
        ];

        $priority = array($priority, $this->max--);
        $this->getSplQueue()->insert($data, $priority);
        return $this;
    }
135531
private function orderByPriority(array $elements)
    {
        // Drop keys from the elements array
        $elements = array_values($elements);
        $length = count($elements);
        for ($i = 0; $i < $length; $i++) {
            for ($j = $i; $j < $length; $j++) {
                $priorityFirst = isset($elements[$i]['priority']) ? (int) $elements[$i]['priority'] : 1;
                $prioritySecond = isset($elements[$j]['priority']) ? (int) $elements[$j]['priority'] : 1;

                if ($priorityFirst < $prioritySecond) {
                    $aux = $elements[$j];
                    $elements[$j] = $elements[$i];
                    $elements[$i] = $aux;
                }
            }
        }

        return $elements;
    }
1373340
public function setElement($element = null)
    {
        $this->element = null;

        if (!$element = $this->internalResolveElement($element)) {
            $this->element = $this->elementId = null;
        } else {
            /** @var Element $element */
            $this->elementId = $element->id;
            $this->element = $element;
        }

        return $this;
    }
1163242
public function insertElement(AbstractElement $element)
	{
		if (!($element instanceof $this->elementClassName)) {
			throw new \InvalidArgumentException("Indexed element must be instance of " . $this->elementClassName);
		}

		$id = $element->getId();

		if (isset($this->elements[$id])) {
			throw new DuplicateElementException("Element \"$id\" already indexed.");
		}

		$this->elements[$id] = $element;

		$indexedAttrs = array_intersect_key($element->getAttributes(), $this->index);
		foreach ($indexedAttrs as $key => $newValue) {
			$this->index[$key][$newValue][$id] = $element;
		}
	}
714494
public function replaceWith(Element $element) 
	{
		// if the element has a parent
		if ( ! empty($this->parent)) {
			$this->parent->replaceChild($this, $element);
		} else {
			throw new \BadMethodCallException(
				__METHOD__."() expects this element to have a parent element"
			);
		}
		
		return $this;
	}
667611
public function add($element)
    {
        if (!$this->contains($element)) {
            $hashIndex = $this->hashIndex($element);

            $this->_items[$hashIndex] = $element;
            $this->_iterator = null;
            return true;
        } else {
            // element already exist
            return false;
        }
    }
272592
protected function addElement($element)
    {
        if($element->getData() == null) {
            throw new Exception("Invalid Element data: null is not allowed.");
        }
        if ($this->elementExistsWith($element->getData())) {
            $this->addWeightToExisting($element);
        } else {
            $this->elements[] = $element;
        }

        return $this;
    }
853248
function addInitializer(iContainerInitializer $initializer, $priority = null)
    {
        $priority = ($priority == null)
            ? ( ($initializer->getPriority() !== null) ? $initializer->getPriority() : 10)
            : $priority;

        $this->_getPriorityQueue()->insert($initializer, $priority);
        return $this;
    }