<s> import collections <EOL> from combi . _python_toolbox import caching <EOL> class _FixedMapManagingMixin ( object ) : <EOL> '''<STR_LIT>''' <EOL> @ caching . CachedProperty <EOL> def fixed_indices ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not self . fixed_map : <EOL> return ( ) <EOL> return tuple ( map ( self . domain . index , self . fixed_map ) ) <EOL> free_indices = caching . CachedProperty ( <EOL> lambda self : tuple ( item for item in range ( self . sequence_length ) <EOL> if item not in self . _undapplied_fixed_map . keys ( ) ) , <EOL> doc = '''<STR_LIT>''' <EOL> ) <EOL> free_keys = caching . CachedProperty ( <EOL> lambda self : tuple ( item for item in self . domain <EOL> if item not in self . fixed_map . keys ( ) ) , <EOL> doc = '''<STR_LIT>''' <EOL> ) <EOL> @ caching . CachedProperty <EOL> def free_values ( self ) : <EOL> '''<STR_LIT>''' <EOL> from combi . _python_toolbox . nifty_collections import Bag <EOL> free_values = [ ] <EOL> fixed_counter = Bag ( self . fixed_map . values ( ) ) <EOL> for item in self . sequence : <EOL> if fixed_counter [ item ] : <EOL> fixed_counter [ item ] -= <NUM_LIT:1> <EOL> else : <EOL> free_values . append ( item ) <EOL> return tuple ( free_values ) <EOL> @ caching . CachedProperty <EOL> def _n_cycles_in_fixed_items_of_just_fixed ( self ) : <EOL> '''<STR_LIT>''' <EOL> unvisited_items = set ( self . _undapplied_unrapplied_fixed_map ) <EOL> n_cycles = <NUM_LIT:0> <EOL> while unvisited_items : <EOL> starting_item = current_item = next ( iter ( unvisited_items ) ) <EOL> while current_item in unvisited_items : <EOL> unvisited_items . remove ( current_item ) <EOL> current_item = self . _undapplied_unrapplied_fixed_map [ current_item ] <EOL> if current_item == starting_item : <EOL> n_cycles += <NUM_LIT:1> <EOL> return n_cycles <EOL> @ caching . CachedProperty <EOL> def _undapplied_fixed_map ( self ) : <EOL> if self . is_dapplied : <EOL> return dict ( ( self . domain . index ( key ) , value ) for key , value <EOL> in self . fixed_map . items ( ) ) <EOL> else : <EOL> return self . fixed_map <EOL> @ caching . CachedProperty <EOL> def _undapplied_unrapplied_fixed_map ( self ) : <EOL> if self . is_dapplied or self . is_rapplied : <EOL> return dict ( ( self . domain . index ( key ) , self . sequence . index ( value ) ) <EOL> for key , value in self . fixed_map . items ( ) ) <EOL> else : <EOL> return self . fixed_map <EOL> @ caching . CachedProperty <EOL> def _free_values_purified_perm_space ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . is_fixed : <EOL> return PermSpace ( <EOL> len ( self . free_indices ) , <EOL> n_elements = self . n_elements - len ( self . fixed_map ) <EOL> ) <EOL> else : <EOL> return self . purified <EOL> _free_values_unsliced_perm_space = caching . CachedProperty ( <EOL> lambda self : self . _free_values_purified_perm_space . get_degreed ( <EOL> ( degree - self . _n_cycles_in_fixed_items_of_just_fixed <EOL> for degree in self . degrees ) <EOL> if self . is_degreed else None ) . get_rapplied ( self . free_values ) . <EOL> get_dapplied ( self . free_keys ) . <EOL> get_partialled ( self . n_elements - len ( self . fixed_map ) ) , <EOL> ) </s>
