Package es.uam.eps.ir.relison.index.fast
Class FastUnweightedPairwiseRelation<W>
java.lang.Object
es.uam.eps.ir.relison.index.fast.FastUnweightedRelation<W>
es.uam.eps.ir.relison.index.fast.FastUnweightedPairwiseRelation<W>
- Type Parameters:
W
- type of the weights.
- All Implemented Interfaces:
Relation<W>
public class FastUnweightedPairwiseRelation<W> extends FastUnweightedRelation<W>
Unweighted relation between different types of objects.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.util.List<java.lang.Integer>>
firstIdxList
Links from the first kind of objects to the second.private java.util.List<java.util.List<java.lang.Integer>>
secondIdxList
Links from the second kind of objects to the first. -
Constructor Summary
Constructors Constructor Description FastUnweightedPairwiseRelation()
Constructor.FastUnweightedPairwiseRelation(java.util.List<java.util.List<java.lang.Integer>> weightList)
Constructor. -
Method Summary
Modifier and Type Method Description boolean
addFirstItem(int firstIdx)
Adds a new item to the relation (if it does not previously exist).boolean
addRelation(int firstIdx, int secondIdx, W weight)
Adds a new relation (if it does not previously exist)boolean
addSecondItem(int secondIdx)
Adds a new second item to the relation (if it does not previously exist).private java.lang.Integer
binarySearch(int firstIdx, int secondIdx, boolean firstList)
Given a pair (firstIdx, secondIdx), finds it in the graph using binary search.boolean
containsPair(int firstIdx, int secondIdx)
Returns whether there is a relation between two objects.java.util.stream.Stream<java.lang.Integer>
getAllFirst()
Gets all the elements of the first type.java.util.stream.Stream<java.lang.Integer>
getAllSecond()
Gets all the elements of the second type.java.util.stream.Stream<IdxValue<W>>
getIdsFirst(int secondIdx)
Gets all the identifiers of items related to a second identifier.java.util.stream.Stream<IdxValue<W>>
getIdsSecond(int firstdIdx)
Gets all the identifiers of items related to a first identifier.W
getValue(int firstIdx, int secondIdx)
Obtains the weight of a relation.int
numFirst()
Gets the total number of elements of the first item in the relation.int
numFirst(int secondIdx)
Gets the total number of elements of the first item related to a second item.int
numSecond()
Gets the total number of elements of the second item in the relation.int
numSecond(int firstIdx)
Gets the total number of elements of the second item related to a first item.boolean
removePair(int firstIdx, int secondIdx)
Removes a pair.boolean
updatePair(int firstIdx, int secondIdx, W weight, boolean createRelation)
Updates the weight of a pair.Methods inherited from class es.uam.eps.ir.relison.index.fast.FastUnweightedRelation
firstsWithSeconds, getIsolatedFirsts, getIsolatedSeconds, hasFirsts, hasSeconds, secondsWithFirsts
-
Field Details
-
firstIdxList
private final java.util.List<java.util.List<java.lang.Integer>> firstIdxListLinks from the first kind of objects to the second. Indexed by the second. E.g. incident edges. -
secondIdxList
private final java.util.List<java.util.List<java.lang.Integer>> secondIdxListLinks from the second kind of objects to the first. Indexed by the first. E.g. outgoing edges.
-
-
Constructor Details
-
FastUnweightedPairwiseRelation
public FastUnweightedPairwiseRelation()Constructor. Builds an empty autorelation. -
FastUnweightedPairwiseRelation
public FastUnweightedPairwiseRelation(java.util.List<java.util.List<java.lang.Integer>> weightList)Constructor. Builds an autorelation from previous information.- Parameters:
weightList
- List of weights.
-
-
Method Details
-
numFirst
public int numFirst()Description copied from interface:Relation
Gets the total number of elements of the first item in the relation. -
numFirst
public int numFirst(int secondIdx)Description copied from interface:Relation
Gets the total number of elements of the first item related to a second item. -
numSecond
public int numSecond()Description copied from interface:Relation
Gets the total number of elements of the second item in the relation.- Returns:
- the number of different elements of the second item in the relation.
-
numSecond
public int numSecond(int firstIdx)Description copied from interface:Relation
Gets the total number of elements of the second item related to a first item. -
getAllFirst
public java.util.stream.Stream<java.lang.Integer> getAllFirst()Description copied from interface:Relation
Gets all the elements of the first type.- Specified by:
getAllFirst
in interfaceRelation<W>
- Overrides:
getAllFirst
in classFastUnweightedRelation<W>
- Returns:
- A stream containing all the elements.
-
getAllSecond
public java.util.stream.Stream<java.lang.Integer> getAllSecond()Description copied from interface:Relation
Gets all the elements of the second type.- Returns:
- A stream containing all the elements.
-
getIdsFirst
Description copied from interface:Relation
Gets all the identifiers of items related to a second identifier.- Specified by:
getIdsFirst
in interfaceRelation<W>
- Overrides:
getIdsFirst
in classFastUnweightedRelation<W>
- Parameters:
secondIdx
- Identifier of the second object.- Returns:
- A stream containing all the weights of the first items.
-
getIdsSecond
Description copied from interface:Relation
Gets all the identifiers of items related to a first identifier.- Specified by:
getIdsSecond
in interfaceRelation<W>
- Overrides:
getIdsSecond
in classFastUnweightedRelation<W>
- Parameters:
firstdIdx
- Identifier of the first object.- Returns:
- A stream containing all the weights of the second items.
-
addFirstItem
public boolean addFirstItem(int firstIdx)Description copied from interface:Relation
Adds a new item to the relation (if it does not previously exist).- Specified by:
addFirstItem
in interfaceRelation<W>
- Overrides:
addFirstItem
in classFastUnweightedRelation<W>
- Parameters:
firstIdx
- Identifier of the first item.- Returns:
- true if everything went OK, false if it did previously exist, or something went wrong.
-
addSecondItem
public boolean addSecondItem(int secondIdx)Description copied from interface:Relation
Adds a new second item to the relation (if it does not previously exist).- Parameters:
secondIdx
- Identifier of the second item.- Returns:
- true if everything went OK, false if it did previously exist, or something went wrong.
-
addRelation
Description copied from interface:Relation
Adds a new relation (if it does not previously exist)- Specified by:
addRelation
in interfaceRelation<W>
- Overrides:
addRelation
in classFastUnweightedRelation<W>
- Parameters:
firstIdx
- Identifier of the first object.secondIdx
- Identifier of the second object.weight
- Weight of the relation.- Returns:
- true if everything went OK, false if it did previously exist, or something went wrong.
-
getValue
Description copied from interface:Relation
Obtains the weight of a relation. -
containsPair
public boolean containsPair(int firstIdx, int secondIdx)Description copied from interface:Relation
Returns whether there is a relation between two objects.- Specified by:
containsPair
in interfaceRelation<W>
- Overrides:
containsPair
in classFastUnweightedRelation<W>
- Parameters:
firstIdx
- Identifier of the first object.secondIdx
- Identifier of the second object- Returns:
- true if it exists, false otherwise.
-
updatePair
Description copied from interface:Relation
Updates the weight of a pair.- Specified by:
updatePair
in interfaceRelation<W>
- Overrides:
updatePair
in classFastUnweightedRelation<W>
- Parameters:
firstIdx
- Index of the first element.secondIdx
- Index of the second element.weight
- New weight for the element.createRelation
- If true, adds the new relation.- Returns:
- true if everything went ok, false if not.
-
removePair
public boolean removePair(int firstIdx, int secondIdx)Description copied from interface:Relation
Removes a pair.- Specified by:
removePair
in interfaceRelation<W>
- Overrides:
removePair
in classFastUnweightedRelation<W>
- Parameters:
firstIdx
- Index of the first element.secondIdx
- Index of the second element.- Returns:
- true if everything went ok, false if not.
-
binarySearch
private java.lang.Integer binarySearch(int firstIdx, int secondIdx, boolean firstList)Given a pair (firstIdx, secondIdx), finds it in the graph using binary search.- Parameters:
firstIdx
- The first element.secondIdx
- The second element.firstList
- True if the element has to be found on the list of first elements, false if it has to be found on the list of second elements.- Returns:
- the index of the element if it exists, - (insertpoint - 1) if it does not, where insertpoint is the corresponding point where the element should be added.
-