shithub: mc

ref: 064b5d2b2f9c54fcbd0e928d75253032e51f7e6f
dir: /libstd/slinsert.myr/

View raw version
use "types.use"
use "alloc.use"
use "die.use"
use "fmt.use"

pkg std =
	generic slinsert	: (sl : @a[:], idx : size, elt : @a	-> @a[:])
;;

generic slinsert = {sl, idx, elt
	var i
	var len

	len = sl.len
	sl = slgrow(sl, sl.len + 1)
	for i = len - 1; i >= idx; i--
		sl[i + 1] = sl[i]
	;;
	sl[idx] = elt
	-> sl
}