(defsubst comp-vec-length (vec)
"Return the number of elements of VEC."
- (+ (comp-vec-beg vec) (comp-vec-end vec)))
+ (- (comp-vec-end vec) (comp-vec-beg vec)))
(defsubst comp-vec--verify-idx (vec idx)
"Check idx is in bounds for VEC."
"Return the element of VEC at index IDX."
(declare (gv-setter (lambda (val)
`(comp-vec--verify-idx ,vec ,idx)
- `(puthash ,idx ,val (comp-vec-data ,vec)))))
+ `(puthash ,idx ,val (comp-vec-data ,vec)))))
(comp-vec--verify-idx vec idx)
(gethash idx (comp-vec-data vec)))
(defsubst comp-vec-append (vec elt)
"Append ELT into VEC.
ELT is returned."
- (puthash (comp-vec-end vec) elt (comp-vec-aref vec))
+ (puthash (comp-vec-end vec) elt (comp-vec-data vec))
(cl-incf (comp-vec-end vec))
elt)
(defsubst comp-vec-prepend (vec elt)
"Prepend ELT into VEC.
ELT is returned."
- (puthash (comp-vec-beg vec) elt (comp-vec-aref vec))
+ (puthash (1- (comp-vec-beg vec)) elt (comp-vec-data vec))
(cl-decf (comp-vec-beg vec))
elt)