A Theory Of Preimage Complexity: Data-Structures, Complexity Measures And Applications To Endofunctions And Associated Digraphs