* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
+
+#include <string.h>
+#include "util/u_math.h"
#include "util/u_vector.h"
+/** @file u_vector.c
+ *
+ * A dynamically growable, circular buffer. Elements are added at head and
+ * removed from tail. head and tail are free-running uint32_t indices and we
+ * only compute the modulo with size when accessing the array. This way,
+ * number of bytes in the queue is always head - tail, even in case of
+ * wraparound.
+ */
+
int
u_vector_init(struct u_vector *vector, uint32_t element_size, uint32_t size)
{
- assert(util_is_power_of_two(size));
- assert(element_size < size && util_is_power_of_two(element_size));
+ assert(util_is_power_of_two_nonzero(size));
+ assert(element_size < size && util_is_power_of_two_nonzero(element_size));
vector->head = 0;
vector->tail = 0;