The priority of the item depends of the number of entries published
        in the cache divided by the maximum of entries.
516259
def priority(self, item):
        
        return '%.1f' % max(self.cache[item.pk][0] / self.max_entries, 0.1)
997015
def prioritize():
    

    while True:
        hp_qs = Message.objects.high_priority().using('default')
        mp_qs = Message.objects.medium_priority().using('default')
        lp_qs = Message.objects.low_priority().using('default')
        while hp_qs.count() or mp_qs.count():
            while hp_qs.count():
                for message in hp_qs.order_by("when_added"):
                    yield message
            while hp_qs.count() == 0 and mp_qs.count():
                yield mp_qs.order_by("when_added")[0]
        while hp_qs.count() == 0 and mp_qs.count() == 0 and lp_qs.count():
            yield lp_qs.order_by("when_added")[0]
        if Message.objects.non_deferred().using('default').count() == 0:
            break
1302911
public final AbstractItem findOldestItem() throws MessageStoreException
    {
        AbstractItem item = null;
        AbstractItemLink oldestLink = null;
        long oldestPositionSoFar = Long.MAX_VALUE;
        for (int priority = Priorities.LOWEST_PRIORITY; priority <= Priorities.HIGHEST_PRIORITY; priority++)
        {
            LinkedList list = _prioritySublists[priority];
            if (null != list)
            {
                AbstractItemLink link = (AbstractItemLink) list.getHead();
                if (null != link)
                {
                    final long pos = link.getPosition();
                    if (pos < oldestPositionSoFar)
                    {
                        oldestPositionSoFar = pos;
                        oldestLink = link;
                    }
                }
            }
        }
        if (null != oldestLink)
        {
            item = oldestLink.getItem();
        }
        return item;
    }
1267106
@Override
    public void setPriority(int newPriority) {
        if (newPriority >= Thread.MIN_PRIORITY
                && newPriority <= Thread.MAX_PRIORITY) {
            thread.setPriority(newPriority);
        }
    }
978517
def addfirst(self, item, new_priority=None):
        """"""

        with self.lock:

            self_data = self.data

            try:
                priority = self_data[0][1]
                if new_priority is not None:
                    if new_priority < priority:
                        raise ValueError('Priority must be >= '
                                         'highest priority.')
                    else:
                        priority = new_priority
            except IndexError:
                priority = 0 if new_priority is None else new_priority

            self_data.appendleft((item, priority))
            self_items = self.items
            maxlen = self._maxlen

            try:
                self_items[item] += 1
            except TypeError:
                self_items[repr(item)] += 1

            if maxlen is not None and maxlen < len(self_data):
                self._poplast()
181648
protected int getPriority()
   {
      if (tc.isEntryEnabled()) SibTr.entry(this, tc, "getPriority");
      if (tc.isEntryEnabled()) SibTr.exit(this, tc, "getPriority", ""+priority);
      return priority;
   }
114793
def populate(self, priority, address, rtr, data):
        
        assert isinstance(data, bytes)
        self.needs_no_rtr(rtr)
        self.needs_data(data, 6)
        self.set_attributes(priority, address, rtr)
        self.cur = (((data[0] << 8)| data[1]) / 32 ) * 0.0625
        self.min = (((data[2] << 8) | data[3]) / 32 ) * 0.0625
        self.max = (((data[4] << 8) | data[5]) / 32 ) * 0.0625
1035655
private void processSource(FastQueue<AssociatedIndex> matches, int numSource,
							   FastQueue<AssociatedIndex> output ) {
		//set up data structures
		scores.resize(numSource);
		solutions.resize(numSource);
		for( int i =0; i < numSource; i++ ) {
			solutions.data[i] = -1;
		}

		// select best matches
		for( int i = 0; i < matches.size(); i++ ) {
			AssociatedIndex a = matches.get(i);
			int found = solutions.data[a.src];
			if( found != -1 ) {
				if( found == -2 ) {
					// the best solution is invalid because two or more had the same score, see if this is better
					double bestScore = scores.data[a.src];
					int result = type.compareTo(bestScore,a.fitScore);
					if( result < 0 ) {
						// found a better one, use this now
						solutions.data[a.src] = i;
						scores.data[a.src] = a.fitScore;
					}
				} else {
					// see if this new score is better than the current best
					AssociatedIndex currentBest = matches.get( found );
					int result = type.compareTo(currentBest.fitScore,a.fitScore);
					if( result < 0 ) {
						// found a better one, use this now
						solutions.data[a.src] = i;
						scores.data[a.src] = a.fitScore;
					} else if( result == 0 ) {
						// two solutions have the same score
						solutions.data[a.src] = -2;
					}
				}
			} else {
				// no previous match found
				solutions.data[a.src] = i;
				scores.data[a.src] = a.fitScore;
			}
		}

		output.reset();
		for( int i =0; i < numSource; i++ ) {
			int index = solutions.data[i];
			if( index >= 0 ) {
				output.add( matches.get(index) );
			}
		}
	}
51406
def _enforce_size_limit(self, capacity):
        """"""
        while len(self._cache) > capacity:
            key, value = self._cache.popitem(last=False)
            if self._on_evict is not None:
                self._on_evict(key, value)
1166528
def prioritize(self, item, force=False):
        
        with self.condition:
            # If the job is already running (or about to be forced),
            # there is nothing to be done.
            if item in self.working or item in self.force:
                return
            self.queue.remove(item)
            if force:
                self.force.append(item)
            else:
                self.queue.appendleft(item)
            self.condition.notify_all()
1295934
function Cache(maxSize, debug, storage) {
    this.maxSize_ = maxSize || -1;
    this.debug_ = debug || false;
    this.storage_ = storage || new Cache.BasicCacheStorage();

    this.fillFactor_ = .75;

    this.stats_ = {};
    this.stats_['hits'] = 0;
    this.stats_['misses'] = 0;
    this.log_('Initialized cache with size ' + maxSize);
}
1073412
function () {
        var threshold = this.slot.keys.length * 0.9;

        if (this.slot.size < threshold) {
            this.capacity(this.slot.size);
        }
    }
839135
private void allocateNormal(PooledByteBuf<T> buf, int reqCapacity, int normCapacity) {
        if (q050.allocate(buf, reqCapacity, normCapacity) || q025.allocate(buf, reqCapacity, normCapacity) ||
            q000.allocate(buf, reqCapacity, normCapacity) || qInit.allocate(buf, reqCapacity, normCapacity) ||
            q075.allocate(buf, reqCapacity, normCapacity)) {
            return;
        }

        // Add a new chunk.
        PoolChunk<T> c = newChunk(pageSize, maxOrder, pageShifts, chunkSize);
        boolean success = c.allocate(buf, reqCapacity, normCapacity);
        assert success;
        qInit.add(c);
    }
476820
def add_priority_rule(
        db, regexp: str, priority: Optional[int] = None,
) -> int:
    """"""
    with db:
        cur = db.cursor()
        if priority is None:
            cur.execute('SELECT MAX(priority) FROM file_priority')
            highest_priority = cur.fetchone()[0]
            if highest_priority is None:
                priority = 1
            else:
                priority = highest_priority + 1
        cur.execute("""
            INSERT INTO file_priority (regexp, priority)
            VALUES (?, ?)""", (regexp, priority))
        row_id = db.last_insert_rowid()
    return row_id
134613
private void maybeEvictEntries() {
    ArrayList<Entry<K, V>> oldEntries;
    synchronized (this) {
      int maxCount = Math.min(
          mMemoryCacheParams.maxEvictionQueueEntries,
          mMemoryCacheParams.maxCacheEntries - getInUseCount());
      int maxSize = Math.min(
          mMemoryCacheParams.maxEvictionQueueSize,
          mMemoryCacheParams.maxCacheSize - getInUseSizeInBytes());
      oldEntries = trimExclusivelyOwnedEntries(maxCount, maxSize);
      makeOrphans(oldEntries);
    }
    maybeClose(oldEntries);
    maybeNotifyExclusiveEntryRemoval(oldEntries);
  }
151658
boolean allocateTiny(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity) {
        return allocate(cacheForTiny(area, normCapacity), buf, reqCapacity);
    }
152019
function LRU ( max ) {
	this.cache  = {};
	this.max    = max || 1000;
	this.first  = null;
	this.last   = null;
	this.length = 0;
}