Class HashMapHierarchy<O>
- java.lang.Object
-
- elki.utilities.datastructures.hierarchy.HashMapHierarchy<O>
-
- Type Parameters:
O
- Object type (arbitrary!)
- All Implemented Interfaces:
Hierarchy<O>
,ModifiableHierarchy<O>
- Direct Known Subclasses:
VisualizationTree
public class HashMapHierarchy<O> extends java.lang.Object implements ModifiableHierarchy<O>
Centralized hierarchy implementation, using a HashMap of Lists.- Since:
- 0.6.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
HashMapHierarchy.ItrAll
Iterator over all known elements, by insertion order.private class
HashMapHierarchy.ItrAnc
Iterator over all Ancestors.private class
HashMapHierarchy.ItrDesc
Iterator over all descendants.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Object[]
elems
All elements, in insertion order (and will not fail badly if concurrent insertions happen).private java.util.HashMap<O,HashMapHierarchy.Rec<O>>
graph
Reference storage.(package private) int
numelems
Number of all elements.
-
Constructor Summary
Constructors Constructor Description HashMapHierarchy()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(O entry)
Add an entry (initializes data structures).boolean
add(O parent, O child)
Add a parent-child relationship.boolean
contains(O object)
Check if an object is part of a hierarchy.private HashMapHierarchy.Rec<O>
getRec(O obj)
Get a record.It<O>
iterAll()
Iterate over all members.It<O>
iterAncestors(O obj)
Iterate ancestors (recursive parents)It<O>
iterAncestorsSelf(O obj)
Iterate ancestors (recursive parents) and self.It<O>
iterChildren(O obj)
Iterate over the (direct) children.It<O>
iterChildrenReverse(O obj)
Iterate over the (direct) children in reverse order.It<O>
iterDescendants(O obj)
Iterate descendants (recursive children)It<O>
iterDescendantsSelf(O obj)
Iterate descendants (recursive children) and self.It<O>
iterParents(O obj)
Iterate over the (direct) parents.It<O>
iterParentsReverse(O obj)
Iterate over the (direct) parents in reverse order.int
numChildren(O obj)
Get number of childrenint
numParents(O obj)
Get number of (direct) parentsprivate void
putRec(O obj, HashMapHierarchy.Rec<O> rec)
Put a record.boolean
remove(O entry)
Remove an entry and all its parent-child relationships.boolean
remove(O parent, O child)
Remove a parent-child relationship.private void
removeRec(O obj)
Remove a record.boolean
removeSubtree(O entry)
Remove an entry and it's whole subtree (unless the elements are reachable by a different path!)int
size()
Total size - number of objects contained.
-
-
-
Field Detail
-
graph
private final java.util.HashMap<O,HashMapHierarchy.Rec<O>> graph
Reference storage.
-
elems
java.lang.Object[] elems
All elements, in insertion order (and will not fail badly if concurrent insertions happen).
-
numelems
int numelems
Number of all elements.
-
-
Method Detail
-
contains
public boolean contains(O object)
Description copied from interface:Hierarchy
Check if an object is part of a hierarchy.
-
size
public int size()
Description copied from interface:Hierarchy
Total size - number of objects contained.
-
add
public boolean add(O parent, O child)
Description copied from interface:ModifiableHierarchy
Add a parent-child relationship.- Specified by:
add
in interfaceModifiableHierarchy<O>
- Parameters:
parent
- Parentchild
- Child- Returns:
true
if changed
-
add
public boolean add(O entry)
Description copied from interface:ModifiableHierarchy
Add an entry (initializes data structures).- Specified by:
add
in interfaceModifiableHierarchy<O>
- Parameters:
entry
- Entry- Returns:
true
if changed
-
remove
public boolean remove(O parent, O child)
Description copied from interface:ModifiableHierarchy
Remove a parent-child relationship.- Specified by:
remove
in interfaceModifiableHierarchy<O>
- Parameters:
parent
- Parentchild
- Child- Returns:
true
if changed
-
remove
public boolean remove(O entry)
Description copied from interface:ModifiableHierarchy
Remove an entry and all its parent-child relationships.- Specified by:
remove
in interfaceModifiableHierarchy<O>
- Parameters:
entry
- Entry- Returns:
true
if changed
-
removeSubtree
public boolean removeSubtree(O entry)
Description copied from interface:ModifiableHierarchy
Remove an entry and it's whole subtree (unless the elements are reachable by a different path!)- Specified by:
removeSubtree
in interfaceModifiableHierarchy<O>
- Parameters:
entry
- Entry- Returns:
true
if changed
-
numChildren
public int numChildren(O obj)
Description copied from interface:Hierarchy
Get number of children- Specified by:
numChildren
in interfaceHierarchy<O>
- Parameters:
obj
- object to get number of children for- Returns:
- number of children
-
iterChildren
public It<O> iterChildren(O obj)
Description copied from interface:Hierarchy
Iterate over the (direct) children.- Specified by:
iterChildren
in interfaceHierarchy<O>
- Parameters:
obj
- object to get children for- Returns:
- iterator for children
-
iterChildrenReverse
public It<O> iterChildrenReverse(O obj)
Description copied from interface:Hierarchy
Iterate over the (direct) children in reverse order.- Specified by:
iterChildrenReverse
in interfaceHierarchy<O>
- Parameters:
obj
- object to get children for- Returns:
- iterator for children
-
iterDescendants
public It<O> iterDescendants(O obj)
Description copied from interface:Hierarchy
Iterate descendants (recursive children)- Specified by:
iterDescendants
in interfaceHierarchy<O>
- Parameters:
obj
- object to get descendants for- Returns:
- iterator for descendants
-
iterDescendantsSelf
public It<O> iterDescendantsSelf(O obj)
Description copied from interface:Hierarchy
Iterate descendants (recursive children) and self.- Specified by:
iterDescendantsSelf
in interfaceHierarchy<O>
- Parameters:
obj
- object to get descendants for- Returns:
- iterator for descendants
-
numParents
public int numParents(O obj)
Description copied from interface:Hierarchy
Get number of (direct) parents- Specified by:
numParents
in interfaceHierarchy<O>
- Parameters:
obj
- reference object- Returns:
- number of parents
-
iterParents
public It<O> iterParents(O obj)
Description copied from interface:Hierarchy
Iterate over the (direct) parents.- Specified by:
iterParents
in interfaceHierarchy<O>
- Parameters:
obj
- object to get parents for- Returns:
- iterator of parents
-
iterParentsReverse
public It<O> iterParentsReverse(O obj)
Description copied from interface:Hierarchy
Iterate over the (direct) parents in reverse order.- Specified by:
iterParentsReverse
in interfaceHierarchy<O>
- Parameters:
obj
- object to get parents for- Returns:
- iterator of parents
-
iterAncestors
public It<O> iterAncestors(O obj)
Description copied from interface:Hierarchy
Iterate ancestors (recursive parents)- Specified by:
iterAncestors
in interfaceHierarchy<O>
- Parameters:
obj
- object to get ancestors for- Returns:
- iterator for ancestors
-
iterAncestorsSelf
public It<O> iterAncestorsSelf(O obj)
Description copied from interface:Hierarchy
Iterate ancestors (recursive parents) and self.- Specified by:
iterAncestorsSelf
in interfaceHierarchy<O>
- Parameters:
obj
- object to get ancestors for- Returns:
- iterator for ancestors
-
iterAll
public It<O> iterAll()
Description copied from interface:Hierarchy
Iterate over all members.
-
getRec
private HashMapHierarchy.Rec<O> getRec(O obj)
Get a record.- Parameters:
obj
- Key- Returns:
- Record
-
putRec
private void putRec(O obj, HashMapHierarchy.Rec<O> rec)
Put a record.- Parameters:
obj
- Keyrec
- Record
-
removeRec
private void removeRec(O obj)
Remove a record.- Parameters:
obj
- Key
-
-