Browse Source

Rename dynarray-append to dynarray-push

* Rename dynstring-concat to dynstring-append
windows-imgui
Macoy Madson 5 months ago
parent
commit
90cdfbd62d
  1. 22
      src/DynamicArray.cake

22
src/DynamicArray.cake

@ -19,7 +19,7 @@
(def-c-function-alias dynarray-free arrfree) ;; (array (* T))
(def-c-function-alias dynarray-append arrput) ;; (array (* T) item T)
(def-c-function-alias dynarray-push arrput) ;; (array (* T) item T)
(def-c-function-alias dynarray-pop arrpop) ;; (array (* T) &return T)
(def-c-function-alias dynarray-insert arrins) ;; (array (* T) index int item T)
(def-c-function-alias dynarray-delete arrdel) ;; (array (* T) index int)
@ -117,7 +117,7 @@
(return num-chars-required))
;; Returns the length of the string, not including the null terminator
(defun dynstring-concat (str (* dynstring) append-str (* (const char)) &return int)
(defun dynstring-append (str (* dynstring) append-str (* (const char)) &return int)
;; Things will go bad if these aren't equal
(assert (!= (deref str) append-str))
@ -127,11 +127,11 @@
;; using strcat may be faster if it is optimized. I won't worry about it for now
(each-char-in-string-const append-str current-char
;; Will resize if necessary
(dynarray-append (deref str) (deref current-char)))
;; Will resize if necessary
(dynarray-push (deref str) (deref current-char)))
;; Add the null terminator
(dynarray-append (deref str) 0)
(dynarray-push (deref str) 0)
(return (dynstring-strlen (deref str))))
;; dynarray-length includes the null terminator. This function removes it
@ -156,11 +156,11 @@
(c-import "stdio.h")
(defun test--dynamic-array (&return int)
(var my-dynarray (* int) null)
(dynarray-append my-dynarray 1)
(dynarray-append my-dynarray 2)
(dynarray-append my-dynarray 3)
(dynarray-append my-dynarray 4)
(dynarray-append my-dynarray 5)
(dynarray-push my-dynarray 1)
(dynarray-push my-dynarray 2)
(dynarray-push my-dynarray 3)
(dynarray-push my-dynarray 4)
(dynarray-push my-dynarray 5)
(unless (and (= 5 (dynarray-length my-dynarray))
(= 2 (at 1 my-dynarray)))
(return 1))
@ -184,7 +184,7 @@
(fprintf stderr "\nItems with addresses:\n")
(each-item-addr-in-dynarray my-dynarray i current-int (* int)
(fprintf stderr "%d %p\n" (deref current-int) current-int))
(fprintf stderr "%d %p\n" (deref current-int) current-int))
(fprintf stderr "\nCapacity after all that: %d\n"
(type-cast (dynarray-capacity my-dynarray) int))

Loading…
Cancel
Save