Serializable
, Iterable<Type>
public class Bag<Type extends Item<K>,K> extends Object implements Serializable, Iterable<Type>
Modifier and Type | Field | Description |
---|---|---|
private int |
capacity |
defined in different bags
|
private int |
currentCounter |
maximum number of items to be taken out at current level
|
private int |
currentLevel |
current take out level
|
private Distributor |
DISTRIBUTOR |
shared DISTRIBUTOR that produce the probability distribution
|
private ArrayList<ArrayList<Type>> |
itemTable |
array of lists of items, for items on different level
|
private int |
levelIndex |
index to get next level, kept in individual objects
|
private int |
mass |
current sum of occupied level
|
private HashMap<K,Type> |
nameTable |
mapping from key to item
|
private int |
THRESHOLD |
firing threshold
|
private int |
TOTAL_LEVEL |
priority levels
|
Constructor | Description |
---|---|
Bag(int levels,
int capacity,
int thresholdLevel) |
thresholdLevel = 0 disables "fire level completely" threshold effect
|
Bag(int levels,
int capacity,
Parameters narParameters) |
Modifier and Type | Method | Description |
---|---|---|
void |
clear() |
|
boolean |
contains(Type it) |
Check if an item is in the bag
|
protected boolean |
emptyLevel(int n) |
Check whether a level is empty
|
Type |
get(K key) |
Get an Item by key
|
float |
getAveragePriority() |
Get the average priority of Items
|
private int |
getLevel(Type item) |
Decide the put-in level according to priority
|
private Type |
intoBase(Type newItem) |
Insert an item into the itemTable, and return the overflow
|
Iterator<Type> |
iterator() |
|
protected void |
outOfBase(Type oldItem) |
Remove an item from itemTable, then adjust mass
|
Type |
pickOut(K key) |
Pick an item by key, then remove it from the bag
|
Type |
pickOut(Type val) |
|
Type |
putBack(Type oldItem,
float forgetCycles,
Memory m) |
Put an item back into the itemTable
|
Type |
putIn(Type newItem) |
Add a new Item into the Bag
|
(package private) String |
showSizes() |
|
int |
size() |
|
Type |
takeOut() |
Choose an Item according to priority distribution and take it out of the Bag
|
private Type |
takeOutFirst(int level) |
Take out the first or last Type in a level from the itemTable
|
String |
toString() |
Collect Bag content into a String for display
|
String |
toStringLong() |
TODO bad paste from preceding
|
forEach, spliterator
private final int TOTAL_LEVEL
private final int THRESHOLD
private final Distributor DISTRIBUTOR
private ArrayList<ArrayList<Type extends Item<K>>> itemTable
private final int capacity
private int mass
private int levelIndex
private int currentLevel
private int currentCounter
public Bag(int levels, int capacity, Parameters narParameters)
public Bag(int levels, int capacity, int thresholdLevel)
public void clear()
public float getAveragePriority()
public boolean contains(Type it)
it
- An itempublic Type get(K key)
key
- The key of the Itempublic Type putIn(Type newItem)
newItem
- The new Itempublic Type putBack(Type oldItem, float forgetCycles, Memory m)
The only place where the forgetting rate is applied
oldItem
- The Item to put backm
- related memorypublic Type takeOut()
public Type pickOut(K key)
key
- The given keyprotected boolean emptyLevel(int n)
n
- The level indexprivate int getLevel(Type item)
item
- The Item to put inprivate Type intoBase(Type newItem)
newItem
- The Item to put inprivate Type takeOutFirst(int level)
level
- The current levelprotected void outOfBase(Type oldItem)
oldItem
- The Item to be removedpublic String toString()
public String toStringLong()
String showSizes()
public int size()
Copyright © 2020 OpenNARS. All rights reserved.