small_array.odin 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. package container_small_array
  2. import "base:builtin"
  3. @require import "base:intrinsics"
  4. @require import "base:runtime"
  5. /*
  6. A fixed-size stack-allocated array operated on in a dynamic fashion.
  7. Fields:
  8. - `data`: The underlying array
  9. - `len`: Amount of items that the `Small_Array` currently holds
  10. Example:
  11. import "core:container/small_array"
  12. example :: proc() {
  13. a: small_array.Small_Array(100, int)
  14. small_array.push_back(&a, 10)
  15. }
  16. */
  17. Small_Array :: struct($N: int, $T: typeid) where N >= 0 {
  18. data: [N]T,
  19. len: int,
  20. }
  21. /*
  22. Returns the amount of items in the small-array.
  23. **Inputs**
  24. - `a`: The small-array
  25. **Returns**
  26. - the amount of items in the array
  27. */
  28. len :: proc "contextless" (a: $A/Small_Array) -> int {
  29. return a.len
  30. }
  31. /*
  32. Returns the capacity of the small-array.
  33. **Inputs**
  34. - `a`: The small-array
  35. **Returns** the capacity
  36. */
  37. cap :: proc "contextless" (a: $A/Small_Array) -> int {
  38. return builtin.len(a.data)
  39. }
  40. /*
  41. Returns how many more items the small-array could fit.
  42. **Inputs**
  43. - `a`: The small-array
  44. **Returns**
  45. - the number of unused slots
  46. */
  47. space :: proc "contextless" (a: $A/Small_Array) -> int {
  48. return builtin.len(a.data) - a.len
  49. }
  50. /*
  51. Returns a slice of the data.
  52. **Inputs**
  53. - `a`: The pointer to the small-array
  54. **Returns**
  55. - the slice
  56. Example:
  57. import "core:container/small_array"
  58. import "core:fmt"
  59. slice_example :: proc() {
  60. print :: proc(a: ^small_array.Small_Array($N, int)) {
  61. for item in small_array.slice(a) {
  62. fmt.println(item)
  63. }
  64. }
  65. a: small_array.Small_Array(5, int)
  66. small_array.push_back(&a, 1)
  67. small_array.push_back(&a, 2)
  68. print(&a)
  69. }
  70. Output:
  71. 1
  72. 2
  73. */
  74. slice :: proc "contextless" (a: ^$A/Small_Array($N, $T)) -> []T {
  75. return a.data[:a.len]
  76. }
  77. /*
  78. Get a copy of the item at the specified position.
  79. This operation assumes that the small-array is large enough.
  80. This will result in:
  81. - the value if 0 <= index < len
  82. - raise a bounds check error if capacity <= index
  83. - the previous value if len < index < capacity, which defauls to T's zero value.
  84. e.g. if you call `small_array.push(&a, 0, 1, 2)`, and `i := pop_back(&a)`,
  85. then `get(a, 2)` will return the earlier value `2` at that location.
  86. See also `get_safe`, which returns T's zero value and `false` if `index` is out of bounds.
  87. **Inputs**
  88. - `a`: The small-array
  89. - `index`: The position of the item to get
  90. **Returns**
  91. - the element at the specified position
  92. */
  93. get :: proc "contextless" (a: $A/Small_Array($N, $T), index: int) -> T {
  94. return a.data[index]
  95. }
  96. /*
  97. Get a pointer to the item at the specified position.
  98. This operation assumes that the small-array is large enough.
  99. This will result in:
  100. - the pointer if 0 <= index < len
  101. - raise a bounds check error if capacity <= index
  102. - a pointer to the previous value if len < index < capacity, which defauls to T's zero value.
  103. e.g. if you call `small_array.push(&a, 0, 1, 2)`, and `i := pop_back(&a)`,
  104. then `get_ptr(a, 2)` will return a pointer to the slot containing the earlier value `2` at that location.
  105. See also `get_ptr_safe`, which returns a nil pointer, and `false` if `index` is out of bounds.
  106. **Inputs**
  107. - `a`: A pointer to the small-array
  108. - `index`: The position of the item to get
  109. **Returns**
  110. - the pointer to the element at the specified position
  111. */
  112. get_ptr :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int) -> ^T {
  113. return &a.data[index]
  114. }
  115. /*
  116. Attempt to get a copy of the item at the specified position.
  117. **Inputs**
  118. - `a`: The small-array
  119. - `index`: The position of the item to get
  120. **Returns**
  121. - the element at the specified position
  122. - true if element exists, false otherwise
  123. Example:
  124. import "core:container/small_array"
  125. import "core:fmt"
  126. get_safe_example :: proc() {
  127. a: small_array.Small_Array(5, rune)
  128. small_array.push_back(&a, 'A')
  129. fmt.println(small_array.get_safe(a, 0) or_else 'x')
  130. fmt.println(small_array.get_safe(a, 1) or_else 'x')
  131. }
  132. Output:
  133. A
  134. x
  135. */
  136. get_safe :: proc "contextless" (a: $A/Small_Array($N, $T), index: int) -> (T, bool) #no_bounds_check {
  137. if index < 0 || index >= a.len {
  138. return {}, false
  139. }
  140. return a.data[index], true
  141. }
  142. /*
  143. Get a pointer to the item at the specified position.
  144. **Inputs**
  145. - `a`: A pointer to the small-array
  146. - `index`: The position of the item to get
  147. **Returns**
  148. - the pointer to the element at the specified position
  149. - true if element exists, false otherwise
  150. */
  151. get_ptr_safe :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int) -> (^T, bool) #no_bounds_check {
  152. if index < 0 || index >= a.len {
  153. return {}, false
  154. }
  155. return &a.data[index], true
  156. }
  157. /*
  158. Set the element at the specified position to the given value.
  159. This operation assumes that the small-array is large enough.
  160. This will result in:
  161. - the value being set if 0 <= index < capacity
  162. - 'crash' otherwise
  163. **Inputs**
  164. - `a`: A pointer to the small-array
  165. - `index`: The position of the item to set
  166. - `value`: The value to set the element to
  167. Example:
  168. import "core:container/small_array"
  169. import "core:fmt"
  170. set_example :: proc() {
  171. a: small_array.Small_Array(5, rune)
  172. small_array.push_back(&a, 'A')
  173. small_array.push_back(&a, 'B')
  174. fmt.println(small_array.slice(&a))
  175. // updates index 0
  176. small_array.set(&a, 0, 'Z')
  177. fmt.println(small_array.slice(&a))
  178. // updates to a position x, where
  179. // len <= x < cap are not visible since
  180. // the length of the small-array remains unchanged
  181. small_array.set(&a, 2, 'X')
  182. small_array.set(&a, 3, 'Y')
  183. small_array.set(&a, 4, 'Z')
  184. fmt.println(small_array.slice(&a))
  185. // resizing makes the change visible
  186. small_array.non_zero_resize(&a, 100)
  187. fmt.println(small_array.slice(&a))
  188. }
  189. Output:
  190. [A, B]
  191. [Z, B]
  192. [Z, B]
  193. [Z, B, X, Y, Z]
  194. */
  195. set :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, item: T) {
  196. a.data[index] = item
  197. }
  198. /*
  199. Tries to resize the small-array to the specified length.
  200. The memory of added elements will be zeroed out.
  201. The new length will be:
  202. - `length` if `length` <= capacity
  203. - capacity if length > capacity
  204. **Inputs**
  205. - `a`: A pointer to the small-array
  206. - `length`: The new desired length
  207. Example:
  208. import "core:container/small_array"
  209. import "core:fmt"
  210. resize_example :: proc() {
  211. a: small_array.Small_Array(5, int)
  212. small_array.push_back(&a, 1)
  213. small_array.push_back(&a, 2)
  214. fmt.println(small_array.slice(&a))
  215. small_array.resize(&a, 1)
  216. fmt.println(small_array.slice(&a))
  217. small_array.resize(&a, 100)
  218. fmt.println(small_array.slice(&a))
  219. }
  220. Output:
  221. [1, 2]
  222. [1]
  223. [1, 0, 0, 0, 0]
  224. */
  225. resize :: proc "contextless" (a: ^$A/Small_Array($N, $T), length: int) {
  226. prev_len := a.len
  227. a.len = min(length, builtin.len(a.data))
  228. if prev_len < a.len {
  229. intrinsics.mem_zero(&a.data[prev_len], size_of(T)*(a.len-prev_len))
  230. }
  231. }
  232. /*
  233. Tries to resize the small-array to the specified length.
  234. The new length will be:
  235. - `length` if `length` <= capacity
  236. - capacity if length > capacity
  237. **Inputs**
  238. - `a`: A pointer to the small-array
  239. - `length`: The new desired length
  240. Example:
  241. import "core:container/small_array"
  242. import "core:fmt"
  243. non_zero_resize_example :: proc() {
  244. a: small_array.Small_Array(5, int)
  245. small_array.push_back(&a, 1)
  246. small_array.push_back(&a, 2)
  247. fmt.println(small_array.slice(&a))
  248. small_array.non_zero_resize(&a, 1)
  249. fmt.println(small_array.slice(&a))
  250. small_array.non_zero_resize(&a, 100)
  251. fmt.println(small_array.slice(&a))
  252. }
  253. Output:
  254. [1, 2]
  255. [1]
  256. [1, 2, 0, 0, 0]
  257. */
  258. non_zero_resize :: proc "contextless" (a: ^$A/Small_Array, length: int) {
  259. a.len = min(length, builtin.len(a.data))
  260. }
  261. /*
  262. Attempts to add the given element to the end.
  263. **Inputs**
  264. - `a`: A pointer to the small-array
  265. - `item`: The item to append
  266. **Returns**
  267. - true if there was enough space to fit the element, false otherwise
  268. Example:
  269. import "core:container/small_array"
  270. import "core:fmt"
  271. push_back_example :: proc() {
  272. a: small_array.Small_Array(2, int)
  273. assert(small_array.push_back(&a, 1), "this should fit")
  274. assert(small_array.push_back(&a, 2), "this should fit")
  275. assert(!small_array.push_back(&a, 3), "this should not fit")
  276. fmt.println(small_array.slice(&a))
  277. }
  278. Output:
  279. [1, 2]
  280. */
  281. push_back :: proc "contextless" (a: ^$A/Small_Array($N, $T), item: T) -> bool {
  282. if a.len < cap(a^) {
  283. a.data[a.len] = item
  284. a.len += 1
  285. return true
  286. }
  287. return false
  288. }
  289. /*
  290. Attempts to add the given element at the beginning.
  291. This operation assumes that the small-array is not empty.
  292. Note: Performing this operation will cause pointers obtained
  293. through get_ptr(_save) to reference incorrect elements.
  294. **Inputs**
  295. - `a`: A pointer to the small-array
  296. - `item`: The item to append
  297. **Returns**
  298. - true if there was enough space to fit the element, false otherwise
  299. Example:
  300. import "core:container/small_array"
  301. import "core:fmt"
  302. push_front_example :: proc() {
  303. a: small_array.Small_Array(2, int)
  304. assert(small_array.push_front(&a, 2), "this should fit")
  305. assert(small_array.push_front(&a, 1), "this should fit")
  306. assert(!small_array.push_back(&a, 0), "this should not fit")
  307. fmt.println(small_array.slice(&a))
  308. }
  309. Output:
  310. [1, 2]
  311. */
  312. push_front :: proc "contextless" (a: ^$A/Small_Array($N, $T), item: T) -> bool {
  313. if a.len < cap(a^) {
  314. a.len += 1
  315. data := slice(a)
  316. copy(data[1:], data[:])
  317. data[0] = item
  318. return true
  319. }
  320. return false
  321. }
  322. /*
  323. Removes and returns the last element of the small-array.
  324. This operation assumes that the small-array is not empty.
  325. **Inputs**
  326. - `a`: A pointer to the small-array
  327. **Returns**
  328. - a copy of the element removed from the end of the small-array
  329. Example:
  330. import "core:container/small_array"
  331. import "core:fmt"
  332. pop_back_example :: proc() {
  333. a: small_array.Small_Array(5, int)
  334. small_array.push(&a, 0, 1, 2)
  335. fmt.println("BEFORE:", small_array.slice(&a))
  336. small_array.pop_back(&a)
  337. fmt.println("AFTER: ", small_array.slice(&a))
  338. }
  339. Output:
  340. BEFORE: [0, 1, 2]
  341. AFTER: [0, 1]
  342. */
  343. pop_back :: proc "odin" (a: ^$A/Small_Array($N, $T), loc := #caller_location) -> T {
  344. assert(condition=(N > 0 && a.len > 0), loc=loc)
  345. item := a.data[a.len-1]
  346. a.len -= 1
  347. return item
  348. }
  349. /*
  350. Removes and returns the first element of the small-array.
  351. This operation assumes that the small-array is not empty.
  352. Note: Performing this operation will cause pointers obtained
  353. through get_ptr(_save) to reference incorrect elements.
  354. **Inputs**
  355. - `a`: A pointer to the small-array
  356. **Returns**
  357. - a copy of the element removed from the beginning of the small-array
  358. Example:
  359. import "core:container/small_array"
  360. import "core:fmt"
  361. pop_front_example :: proc() {
  362. a: small_array.Small_Array(5, int)
  363. small_array.push(&a, 0, 1, 2)
  364. fmt.println("BEFORE:", small_array.slice(&a))
  365. small_array.pop_front(&a)
  366. fmt.println("AFTER: ", small_array.slice(&a))
  367. }
  368. Output:
  369. BEFORE: [0, 1, 2]
  370. AFTER: [1, 2]
  371. */
  372. pop_front :: proc "odin" (a: ^$A/Small_Array($N, $T), loc := #caller_location) -> T {
  373. assert(condition=(N > 0 && a.len > 0), loc=loc)
  374. item := a.data[0]
  375. s := slice(a)
  376. copy(s[:], s[1:])
  377. a.len -= 1
  378. return item
  379. }
  380. /*
  381. Attempts to remove and return the last element of the small array.
  382. Unlike `pop_back`, it does not assume that the array is non-empty.
  383. **Inputs**
  384. - `a`: A pointer to the small-array
  385. **Returns**
  386. - a copy of the element removed from the end of the small-array
  387. - true if the small-array was not empty, false otherwise
  388. Example:
  389. import "core:container/small_array"
  390. pop_back_safe_example :: proc() {
  391. a: small_array.Small_Array(3, int)
  392. small_array.push(&a, 1)
  393. el, ok := small_array.pop_back_safe(&a)
  394. assert(ok, "there was an element in the array")
  395. el, ok = small_array.pop_back_safe(&a)
  396. assert(!ok, "there was NO element in the array")
  397. }
  398. */
  399. pop_back_safe :: proc "contextless" (a: ^$A/Small_Array($N, $T)) -> (item: T, ok: bool) {
  400. if N > 0 && a.len > 0 {
  401. item = a.data[a.len-1]
  402. a.len -= 1
  403. ok = true
  404. }
  405. return
  406. }
  407. /*
  408. Attempts to remove and return the first element of the small array.
  409. Unlike `pop_front`, it does not assume that the array is non-empty.
  410. Note: Performing this operation will cause pointers obtained
  411. through get_ptr(_save) to reference incorrect elements.
  412. **Inputs**
  413. - `a`: A pointer to the small-array
  414. **Returns**
  415. - a copy of the element removed from the beginning of the small-array
  416. - true if the small-array was not empty, false otherwise
  417. Example:
  418. import "core:container/small_array"
  419. pop_front_safe_example :: proc() {
  420. a: small_array.Small_Array(3, int)
  421. small_array.push(&a, 1)
  422. el, ok := small_array.pop_front_safe(&a)
  423. assert(ok, "there was an element in the array")
  424. el, ok = small_array.pop_front_(&a)
  425. assert(!ok, "there was NO element in the array")
  426. }
  427. */
  428. pop_front_safe :: proc "contextless" (a: ^$A/Small_Array($N, $T)) -> (item: T, ok: bool) {
  429. if N > 0 && a.len > 0 {
  430. item = a.data[0]
  431. s := slice(a)
  432. copy(s[:], s[1:])
  433. a.len -= 1
  434. ok = true
  435. }
  436. return
  437. }
  438. /*
  439. Decreases the length of the small-array by the given amount.
  440. The elements are therefore not really removed and can be
  441. recovered by calling `resize`.
  442. Note: This procedure assumes that the array has a sufficient length.
  443. **Inputs**
  444. - `a`: A pointer to the small-array
  445. - `count`: The amount the length should be reduced by
  446. Example:
  447. import "core:container/small_array"
  448. import "core:fmt"
  449. consume_example :: proc() {
  450. a: small_array.Small_Array(3, int)
  451. small_array.push(&a, 0, 1, 2)
  452. fmt.println("BEFORE:", small_array.slice(&a))
  453. small_array.consume(&a, 2)
  454. fmt.println("AFTER :", small_array.slice(&a))
  455. }
  456. Output:
  457. BEFORE: [0, 1, 2]
  458. AFTER : [0]
  459. */
  460. consume :: proc "odin" (a: ^$A/Small_Array($N, $T), count: int, loc := #caller_location) {
  461. assert(condition=a.len >= count, loc=loc)
  462. a.len -= count
  463. }
  464. /*
  465. Removes the element at the specified index while retaining order.
  466. Note: Performing this operation will cause pointers obtained
  467. through get_ptr(_save) to reference incorrect elements.
  468. **Inputs**
  469. - `a`: A pointer to the small-array
  470. - `index`: The position of the element to remove
  471. Example:
  472. import "core:container/small_array"
  473. import "core:fmt"
  474. ordered_remove_example :: proc() {
  475. a: small_array.Small_Array(4, int)
  476. small_array.push(&a, 0, 1, 2, 3)
  477. fmt.println("BEFORE:", small_array.slice(&a))
  478. small_array.ordered_remove(&a, 1)
  479. fmt.println("AFTER :", small_array.slice(&a))
  480. }
  481. Output:
  482. BEFORE: [0, 1, 2, 3]
  483. AFTER : [0, 2, 3]
  484. */
  485. ordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check {
  486. runtime.bounds_check_error_loc(loc, index, a.len)
  487. if index+1 < a.len {
  488. copy(a.data[index:], a.data[index+1:])
  489. }
  490. a.len -= 1
  491. }
  492. /*
  493. Removes the element at the specified index without retaining order.
  494. **Inputs**
  495. - `a`: A pointer to the small-array
  496. - `index`: The position of the element to remove
  497. Example:
  498. import "core:container/small_array"
  499. import "core:fmt"
  500. unordered_remove_example :: proc() {
  501. a: small_array.Small_Array(4, int)
  502. small_array.push(&a, 0, 1, 2, 3)
  503. fmt.println("BEFORE:", small_array.slice(&a))
  504. small_array.unordered_remove(&a, 1)
  505. fmt.println("AFTER :", small_array.slice(&a))
  506. }
  507. Output:
  508. BEFORE: [0, 1, 2, 3]
  509. AFTER : [0, 3, 2]
  510. */
  511. unordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check {
  512. runtime.bounds_check_error_loc(loc, index, a.len)
  513. n := a.len-1
  514. if index != n {
  515. a.data[index] = a.data[n]
  516. }
  517. a.len -= 1
  518. }
  519. /*
  520. Sets the length of the small-array to 0.
  521. **Inputs**
  522. - `a`: A pointer to the small-array
  523. Example:
  524. import "core:container/small_array"
  525. import "core:fmt"
  526. clear_example :: proc() {
  527. a: small_array.Small_Array(4, int)
  528. small_array.push(&a, 0, 1, 2, 3)
  529. fmt.println("BEFORE:", small_array.slice(&a))
  530. small_array.clear(&a)
  531. fmt.println("AFTER :", small_array.slice(&a))
  532. }
  533. Output:
  534. BEFORE: [0, 1, 2, 3]
  535. AFTER : []
  536. */
  537. clear :: proc "contextless" (a: ^$A/Small_Array($N, $T)) {
  538. resize(a, 0)
  539. }
  540. /*
  541. Attempts to append all elements to the small-array returning
  542. false if there is not enough space to fit all of them.
  543. **Inputs**
  544. - `a`: A pointer to the small-array
  545. - `item`: The item to append
  546. - ..:
  547. **Returns**
  548. - true if there was enough space to fit the element, false otherwise
  549. Example:
  550. import "core:container/small_array"
  551. import "core:fmt"
  552. push_back_elems_example :: proc() {
  553. a: small_array.Small_Array(100, int)
  554. small_array.push_back_elems(&a, 0, 1, 2, 3, 4)
  555. fmt.println(small_array.slice(&a))
  556. }
  557. Output:
  558. [0, 1, 2, 3, 4]
  559. */
  560. push_back_elems :: proc "contextless" (a: ^$A/Small_Array($N, $T), items: ..T) -> bool {
  561. if a.len + builtin.len(items) <= cap(a^) {
  562. n := copy(a.data[a.len:], items[:])
  563. a.len += n
  564. return true
  565. }
  566. return false
  567. }
  568. /*
  569. Tries to insert an element at the specified position.
  570. Note: Performing this operation will cause pointers obtained
  571. through get_ptr(_save) to reference incorrect elements.
  572. **Inputs**
  573. - `a`: A pointer to the small-array
  574. - `item`: The item to insert
  575. - `index`: The index to insert the item at
  576. **Returns**
  577. - true if there was enough space to fit the element, false otherwise
  578. Example:
  579. import "core:container/small_array"
  580. import "core:fmt"
  581. inject_at_example :: proc() {
  582. arr: small_array.Small_Array(100, rune)
  583. small_array.push(&arr, 'A', 'C', 'D')
  584. small_array.inject_at(&arr, 'B', 1)
  585. fmt.println(small_array.slice(&arr))
  586. }
  587. Output:
  588. [A, B, C, D]
  589. */
  590. inject_at :: proc "contextless" (a: ^$A/Small_Array($N, $T), item: T, index: int) -> bool #no_bounds_check {
  591. if a.len < cap(a^) && index >= 0 && index <= len(a^) {
  592. a.len += 1
  593. for i := a.len - 1; i >= index + 1; i -= 1 {
  594. a.data[i] = a.data[i - 1]
  595. }
  596. a.data[index] = item
  597. return true
  598. }
  599. return false
  600. }
  601. // Alias for `push_back`
  602. append_elem :: push_back
  603. // Alias for `push_back_elems`
  604. append_elems :: push_back_elems
  605. /*
  606. Tries to append the element(s) to the small-array.
  607. **Inputs**
  608. - `a`: A pointer to the small-array
  609. - `item`: The item to append
  610. - ..:
  611. **Returns**
  612. - true if there was enough space to fit the element, false otherwise
  613. Example:
  614. import "core:container/small_array"
  615. import "core:fmt"
  616. push_example :: proc() {
  617. a: small_array.Small_Array(100, int)
  618. small_array.push(&a, 0)
  619. small_array.push(&a, 1, 2, 3, 4)
  620. fmt.println(small_array.slice(&a))
  621. }
  622. Output:
  623. [0, 1, 2, 3, 4]
  624. */
  625. push :: proc{push_back, push_back_elems}
  626. // Alias for `push`
  627. append :: proc{push_back, push_back_elems}