naRef naVec_get(naRef v, int i);
void naVec_set(naRef vec, int i, naRef o);
int naVec_append(naRef vec, naRef o);
-naRef naVec_removelast(naRef vec);
void naVec_setsize(naContext c, naRef vec, int sz);
+/**
+ * Remove and retrieve the first element of the vector.
+ *
+ * This operation reduces the size of the vector by one and moves all elements
+ * by one towards the begin of the vector.
+ *
+ * @return The element removed from the begin
+ */
+naRef naVec_removefirst(naRef vec);
+
+/**
+ * Remove and retrieve the last element of the vector.
+ *
+ * This operation reduces the size of the vector by one.
+ *
+ * @return The element removed from the end
+ */
+naRef naVec_removelast(naRef vec);
+
// Hash utilities:
int naHash_size(naRef h);
int naHash_get(naRef hash, naRef key, naRef* out);
return 0;
}
+//------------------------------------------------------------------------------
void naVec_setsize(naContext c, naRef vec, int sz)
{
if (sz < 0)
}
}
+//------------------------------------------------------------------------------
+naRef naVec_removefirst(naRef vec)
+{
+ naRef o;
+ int i;
+ if(IS_VEC(vec)) {
+ struct VecRec* v = PTR(vec).vec->rec;
+ if(!v || v->size == 0) return naNil();
+ o = v->array[0];
+ for (i=1; i<v->size; i++)
+ v->array[i-1] = v->array[i];
+ v->size--;
+ if(v->size < (v->alloced >> 1))
+ resize(PTR(vec).vec);
+ return o;
+ }
+ return naNil();
+}
+
+//------------------------------------------------------------------------------
naRef naVec_removelast(naRef vec)
{
naRef o;