public override int IndexOfElement(DomainElement element) { int value = element[0]; if (value < First || value >= Second || element.GetNumberOfComponents() > 1) { throw new Exception("Element not in domain!"); } return(value - First); }
public override int IndexOfElement(DomainElement element) { if (element.GetNumberOfComponents() != GetNumberOfComponents()) { throw new Exception("Element not in domain!"); } int index = 0; int combinations = 1; for (int i = GetNumberOfComponents() - 1; i >= 0; --i) { DomainElement value = DomainElement.Of(element.GetComponentValue(i)); index += (combinations * _domains[i].IndexOfElement(value)); combinations *= _domains[i].GetCardinality(); } return(index); }