Class PreferentialAttachmentCache<T>
- java.lang.Object
-
- uk.gov.gchq.gaffer.randomelementgeneration.cache.PreferentialAttachmentCache<T>
-
- All Implemented Interfaces:
Cache<T>
public class PreferentialAttachmentCache<T> extends Object implements Cache<T>
ACache
that has a maximum size. Each item is associated with a count. As an item is added that count is incremented. If more than the maximum number of items are added then the one with the smallest count is removed. When theget()
method is called, one of the items is returned at random. The probability of each item being returned is proportional to its count - items with large counts are more likely to be returned. When theget()
method is called the count of that item is incremented. The result is that the rich grow richer --- items that are returned become more likely to be returned, and over time some items in the cache will be returned much more often than others.This can be used to generate graphs which are power-law in the number of times elements are added, i.e. by adding elements to both a graph and this cache, and repeatedly also adding the result of calling
get()
on this cache, then some elements will be added many more times that others. This can be used to test the performance when the same element is added multiple times causing many aggregations.
-
-
Constructor Summary
Constructors Constructor Description PreferentialAttachmentCache(int maxSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T t)
T
get()
Returns a random element in proportion to the frequencies.Map<T,Long>
getItemsAndFrequencies()
long
getNumberOfElements()
-
-
-
Method Detail
-
get
public T get()
Returns a random element in proportion to the frequencies. The frequency of the returned item is increased by 1.
-
getNumberOfElements
public long getNumberOfElements()
-
-