MCPcopy
hub / github.com/copy/v86 / ByteQueue

Function ByteQueue

src/lib.js:269–331  ·  view source on GitHub ↗

* @constructor * * Queue wrapper around Uint8Array * Used by devices such as the PS2 controller

(size)

Source from the content-addressed store, hash-verified

267 * Used by devices such as the PS2 controller
268 */
269function ByteQueue(size)
270{
271 var data = new Uint8Array(size),
272 start,
273 end;
274
275 dbg_assert((size & size - 1) === 0);
276
277 this.length = 0;
278
279 this.push = function(item)
280 {
281 if(this.length === size)
282 {
283 // intentional overwrite
284 }
285 else
286 {
287 this.length++;
288 }
289
290 data[end] = item;
291 end = end + 1 & size - 1;
292 };
293
294 this.shift = function()
295 {
296 if(!this.length)
297 {
298 return -1;
299 }
300 else
301 {
302 var item = data[start];
303
304 start = start + 1 & size - 1;
305 this.length--;
306
307 return item;
308 }
309 };
310
311 this.peek = function()
312 {
313 if(!this.length)
314 {
315 return -1;
316 }
317 else
318 {
319 return data[start];
320 }
321 };
322
323 this.clear = function()
324 {
325 start = 0;
326 end = 0;

Callers

nothing calls this directly

Calls 1

dbg_assertFunction · 0.85

Tested by

no test coverage detected