Sha256: 4315271203c261ba86d48a0118d88dc171e4194bbf3717ecdff21526f80df3f7

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
//            Portions ©2008-2011 Apple Inc. All rights reserved.
// License:   Licensed under MIT license (see license.js)
// ==========================================================================
SC.StaticQueue = SC.mixin({},
{
  _content: null,
  
  create: function(max) {
    var ret = SC.beget(this);
    ret._content = [];
    ret._content.length = max;
    
    return ret;
  },
  
  enqueue: function(item) {
    if(this.length >= this._content.length) {
      return;
    }
    
    this._content[this._tail++] = item;
    
    if(this._tail >= this._content.length) this._tail = 0;
    
    this.length++;
    
    return this;
  },
  
  dequeue: function() {
    var ret;
    
    if(this.length > 0) {
      ret = this._content[this._head++];
    } else {
      return null;
    }
    
    if(this._head >= this._content.length) this._head = 0;
    
    this.length--;
    
    return ret;
  },
  
  peek: function(index) {
    index = index || 0;
    return this._content[(this._head + index) % this.length];
  },
  
  length: 0,
  
  _head: 0,
  
  _tail: 0
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sproutcore-1.5.0.rc.2 lib/frameworks/sproutcore/frameworks/foundation/system/staticqueue.js
sproutcore-1.5.0.rc.1 lib/frameworks/sproutcore/frameworks/foundation/system/staticqueue.js