Commit db23a06d authored by John van Groningen's avatar John van Groningen
Browse files

use unique array select and update instead of replace

parent dd4f5c27
......@@ -44,22 +44,18 @@ where
arrayCopy a
:== arrayCopyBegin a1 s
where
(s, a1)
= usize a
(s, a1) = usize a
arrayAndElementsCopy place_holder copy_element_function array
:== copy place_holder array1 (_createArray n) 0 n
arrayAndElementsCopy copy_element_function array
:== copy array1 (_createArray n) 0 n
where
(n, array1)
= usize array
copy place_holder array array_copy i n
(n, array1) = usize array
copy array array_copy i n
| i == n
= (array_copy, array)
// otherwise
# (element, array)
= replace array i place_holder
= (array_copy, array)
# (element, array) = array![i]
# (copy_element, element)
= copy_element_function element
# (place_holder, array)
= replace array i element
= copy place_holder array {array_copy & [i] = copy_element} (i+1) n
# array = {array & [i] = element}
= copy array {array_copy & [i] = copy_element} (i+1) n
......@@ -43,22 +43,18 @@ where
arrayCopy a
:== arrayCopyBegin a1 s
where
(s, a1)
= usize a
(s, a1) = usize a
arrayAndElementsCopy place_holder copy_element_function array
:== copy place_holder array1 (_createArray n) 0 n
arrayAndElementsCopy copy_element_function array
:== copy array1 (_createArray n) 0 n
where
(n, array1)
= usize array
copy place_holder array array_copy i n
(n, array1) = usize array
copy array array_copy i n
| i == n
= (array_copy, array)
// otherwise
# (element, array)
= replace array i place_holder
= (array_copy, array)
# (element, array) = array![i]
# (copy_element, element)
= copy_element_function element
# (place_holder, array)
= replace array i element
= copy place_holder array {array_copy & [i] = copy_element} (i+1) n
# array = {array & [i] = element}
= copy array {array_copy & [i] = copy_element} (i+1) n
......@@ -1409,7 +1409,7 @@ substitute_dep_counts component_members ai_group_counts
where
build_known :: !*{!RefCounts} -> (!*{*{#Bool}},!*{!RefCounts})
build_known t
= arrayAndElementsCopy {} (\e->(createArray (size e) False,e)) t
= arrayAndElementsCopy (\e->(createArray (size e) False,e)) t
subst_non_zero :: ![(!FunIndex,!ArgIndex)] !FunIndex !ArgIndex !FunIndex !ArgIndex !*{*{#Bool}} !*{!RefCounts}-> *{!RefCounts}
subst_non_zero iter fi ai fm am known rcs
......
......@@ -387,14 +387,11 @@ ikhInsert :: !Bool !IntKey a !*(IntKeyHashtable a) -> (!Bool, !.IntKeyHashtable
ikhInsert overide int_key value (IntKeyHashtable ikh_rehash_threshold ikh_nr_of_entries ikh_bitmask ikh_entries)
| ikh_rehash_threshold<=ikh_nr_of_entries
= ikhInsert overide int_key value (grow ikh_entries)
#! hash_value
= int_key bitand ikh_bitmask
(tree, ikh_entries)
= replace ikh_entries hash_value IKT_Leaf
#! hash_value = int_key bitand ikh_bitmask
(tree, ikh_entries) = ikh_entries![hash_value]
(is_new, tree)
= iktUInsert overide int_key value tree
ikh_entries
= { ikh_entries & [hash_value] = tree }
ikh_entries = { ikh_entries & [hash_value] = tree }
| is_new
= (is_new, (IntKeyHashtable ikh_rehash_threshold (ikh_nr_of_entries+1) ikh_bitmask ikh_entries))
= (is_new, (IntKeyHashtable ikh_rehash_threshold ikh_nr_of_entries ikh_bitmask ikh_entries))
......@@ -444,14 +441,11 @@ ikhUSearch :: !IntKey !*(IntKeyHashtable a) -> (!.Optional a, !*IntKeyHashtable
ikhUSearch int_key (IntKeyHashtable ikh_rehash_threshold ikh_nr_of_entries ikh_bitmask ikh_entries)
| size ikh_entries==0
= (No, IntKeyHashtable ikh_rehash_threshold ikh_nr_of_entries ikh_bitmask ikh_entries)
# hash_value
= int_key bitand ikh_bitmask
(ikt, ikh_entries)
= replace ikh_entries hash_value IKT_Leaf
# hash_value = int_key bitand ikh_bitmask
(ikt, ikh_entries) = ikh_entries![hash_value]
(opt_result, ikt)
= iktUSearch int_key ikt
ikh_entries
= { ikh_entries & [hash_value] = ikt }
ikh_entries = { ikh_entries & [hash_value] = ikt }
= (opt_result, (IntKeyHashtable ikh_rehash_threshold ikh_nr_of_entries ikh_bitmask ikh_entries))
iktUInsert :: !Bool !IntKey a !*(IntKeyTree a) -> (!Bool, !.IntKeyTree a)
......
......@@ -21,7 +21,7 @@ implies a b :== not a || b
markExplImpSymbols :: !Int !*(!*ExplImpInfos,!*SymbolTable) -> (!.[Ident],!(!*ExplImpInfos,!*SymbolTable))
markExplImpSymbols component_nr (expl_imp_info, cs_symbol_table)
# (expl_imp_info_from_component,expl_imp_info) = replace expl_imp_info component_nr {}
# (expl_imp_info_from_component,expl_imp_info) = expl_imp_info![component_nr]
#! nr_of_expl_imp_symbols = size expl_imp_info_from_component
# (new_symbols, expl_imp_info_from_component, cs_symbol_table) = iFoldSt (mark_symbol component_nr) 0 nr_of_expl_imp_symbols ([], expl_imp_info_from_component, cs_symbol_table)
expl_imp_info = {expl_imp_info & [component_nr] = expl_imp_info_from_component}
......
......@@ -284,16 +284,16 @@ frontEndInterface options mod_ident search_paths cached_dcl_modules cached_dcl_m
clear_group_indices_of_macros :: !*{#*{#FunDef}} -> *{#*{#FunDef}}
clear_group_indices_of_macros cached_dcl_macros
= clear_group_indices1 0 {} cached_dcl_macros
= clear_group_indices1 0 cached_dcl_macros
where
clear_group_indices1 :: !Int !*{#FunDef} !*{#*{#u:FunDef}} -> *{#*{#FunDef}}
clear_group_indices1 i dummy cached_dcl_macros
clear_group_indices1 :: !Int !*{#*{#u:FunDef}} -> *{#*{#FunDef}}
clear_group_indices1 i cached_dcl_macros
| i==size cached_dcl_macros
= cached_dcl_macros
# (cached_dcl_macros_i,cached_dcl_macros) = replace cached_dcl_macros i dummy
# (cached_dcl_macros_i,cached_dcl_macros) = cached_dcl_macros![i]
# cached_dcl_macros_i = clear_group_indices2 0 cached_dcl_macros_i
# (dummy,cached_dcl_macros) = replace cached_dcl_macros i cached_dcl_macros_i
= clear_group_indices1 (i+1) dummy cached_dcl_macros
# cached_dcl_macros = {cached_dcl_macros & [i]=cached_dcl_macros_i}
= clear_group_indices1 (i+1) cached_dcl_macros
clear_group_indices2 j cached_dcl_macros_i
| j==size cached_dcl_macros_i
......
......@@ -160,7 +160,7 @@ where
clear_modules n td_infos
| n == size td_infos
= td_infos
#! (td_infos1, td_infos) = replace td_infos n {}
#! (td_infos1, td_infos) = td_infos![n]
#! td_infos1 = clear_td_infos 0 td_infos1
#! td_infos = {td_infos & [n]=td_infos1}
= clear_modules (inc n) td_infos
......
......@@ -90,7 +90,7 @@ where
putIdentInHashTable :: !String !IdentClass !*HashTable -> (!BoxedIdent, !*HashTable)
putIdentInHashTable name ident_class {hte_symbol_heap,hte_entries,hte_mark}
# hash_val = hashValue name
(entries,hte_entries) = replace hte_entries hash_val HTE_Empty
(entries,hte_entries) = hte_entries![hash_val]
(ident, hte_symbol_heap, entries) = insert name ident_class hte_mark hte_symbol_heap entries
hte_entries = {hte_entries & [hash_val]=entries}
= (ident, { hte_symbol_heap = hte_symbol_heap, hte_entries = hte_entries,hte_mark=hte_mark })
......@@ -114,9 +114,9 @@ where
putQualifiedIdentInHashTable :: !String !BoxedIdent !IdentClass !*HashTable -> (!BoxedIdent, !*HashTable)
putQualifiedIdentInHashTable module_name ident ident_class {hte_symbol_heap,hte_entries,hte_mark}
# hash_val = hashValue module_name
(entries,hte_entries) = replace hte_entries hash_val HTE_Empty
(entries,hte_entries) = hte_entries![hash_val]
(ident, hte_symbol_heap, entries) = insert module_name ident ident_class (IC_Module NoQualifiedIdents) hte_mark hte_symbol_heap entries
hte_entries = update hte_entries hash_val entries
hte_entries = {hte_entries & [hash_val]=entries}
= (ident, { hte_symbol_heap = hte_symbol_heap, hte_entries = hte_entries,hte_mark=hte_mark })
where
insert :: !String !BoxedIdent !IdentClass !IdentClass !Int !*SymbolTable *HashTableEntry -> (!BoxedIdent, !*SymbolTable, !*HashTableEntry)
......@@ -141,9 +141,9 @@ where
putPredefinedIdentInHashTable :: !Ident !IdentClass !*HashTable -> *HashTable
putPredefinedIdentInHashTable predefined_ident=:{id_name} ident_class {hte_symbol_heap,hte_entries,hte_mark}
# hash_val = hashValue id_name
(entries,hte_entries) = replace hte_entries hash_val HTE_Empty
(entries,hte_entries) = hte_entries![hash_val]
(hte_symbol_heap, entries) = insert id_name ident_class hte_mark hte_symbol_heap entries
hte_entries = update hte_entries hash_val entries
hte_entries = {hte_entries & [hash_val]=entries}
= { hte_symbol_heap = hte_symbol_heap, hte_entries = hte_entries,hte_mark=hte_mark }
where
insert :: !String !IdentClass !Int !*SymbolTable *HashTableEntry -> (!*SymbolTable, !*HashTableEntry)
......@@ -164,9 +164,9 @@ where
get_qualified_idents_from_hash_table :: !Ident !*HashTable -> (!QualifiedIdents,!*HashTable)
get_qualified_idents_from_hash_table module_ident=:{id_name} hash_table=:{hte_entries}
# hash_val = hashValue id_name
(entries,hte_entries) = replace hte_entries hash_val HTE_Empty
(entries,hte_entries) = hte_entries![hash_val]
(qualified_idents, entries) = find_qualified_idents id_name (IC_Module NoQualifiedIdents) entries
hte_entries = update hte_entries hash_val entries
hte_entries = {hte_entries & [hash_val] = entries}
= (qualified_idents, {hash_table & hte_entries = hte_entries})
where
find_qualified_idents :: !String !IdentClass *HashTableEntry -> (!QualifiedIdents, !*HashTableEntry)
......@@ -188,9 +188,9 @@ remove_icl_symbols_from_hash_table hash_table=:{hte_entries}
where
remove_icl_symbols_from_array i hte_entries
| i<size hte_entries
# (entries,hte_entries) = replace hte_entries i HTE_Empty
# (entries,hte_entries) = hte_entries![i]
# (_,entries) = remove_icl_entries_from_tree entries
# hte_entries = update hte_entries i entries
# hte_entries = {hte_entries & [i] = entries}
= remove_icl_symbols_from_array (i+1) hte_entries
= hte_entries
......
......@@ -100,7 +100,7 @@ accCoercionTree f i coercion_trees
:== acc_coercion_tree i coercion_trees
where
acc_coercion_tree i coercion_trees
# (coercion_tree, coercion_trees) = replace coercion_trees i CT_Empty
# (coercion_tree, coercion_trees) = coercion_trees![i]
(x, coercion_tree) = f coercion_tree
= (x, {coercion_trees & [i]=coercion_tree})
......@@ -109,7 +109,7 @@ appCoercionTree f i coercion_trees
:== acc_coercion_tree i coercion_trees
where
acc_coercion_tree i coercion_trees
# (coercion_tree, coercion_trees) = replace coercion_trees i CT_Empty
# (coercion_tree, coercion_trees) = coercion_trees![i]
= {coercion_trees & [i] = f coercion_tree}
class performOnTypeVars a :: !(TypeAttribute TypeVar .st -> .st) !a !.st -> .st
......
......@@ -1739,7 +1739,7 @@ accCoercionTree f i coercion_trees
:== acc_coercion_tree i coercion_trees
where
acc_coercion_tree i coercion_trees
# (coercion_tree, coercion_trees) = replace coercion_trees i CT_Empty
# (coercion_tree, coercion_trees) = coercion_trees![i]
(x, coercion_tree) = f coercion_tree
= (x, {coercion_trees & [i]=coercion_tree})
......@@ -1747,7 +1747,7 @@ appCoercionTree f i coercion_trees
:== acc_coercion_tree i coercion_trees
where
acc_coercion_tree i coercion_trees
# (coercion_tree, coercion_trees) = replace coercion_trees i CT_Empty
# (coercion_tree, coercion_trees) = coercion_trees![i]
= {coercion_trees & [i] = f coercion_tree}
flattenCoercionTree :: !u:CoercionTree -> (![Int], !u:CoercionTree)
......
......@@ -164,7 +164,6 @@ where
= combine_coercion_trees group_index attrs partition merged_tree coer_offered coer_demanded
combine_coercion_trees group_index [ ] partition merged_tree coer_offered coer_demanded
= (merged_tree, coer_demanded)
rebuild_tree :: !Index !AttributePartition !*CoercionTree !*CoercionTree -> *CoercionTree
rebuild_tree group_index partition (CT_Node attr left right) tree
......@@ -669,13 +668,13 @@ coerceAttributes off_attr dem_attr _ coercions
newInequality :: !Int !Int !*Coercions -> *Coercions
newInequality off_attr dem_attr coercions=:{coer_demanded, coer_offered}
# (dem_coercions, coer_demanded) = replace coer_demanded off_attr CT_Empty
# (dem_coercions, coer_demanded) = coer_demanded![off_attr]
(succ, dem_coercions) = insert dem_attr dem_coercions
coer_demanded = { coer_demanded & [off_attr] = dem_coercions }
coer_demanded = {coer_demanded & [off_attr] = dem_coercions}
| succ
# (off_coercions, coer_offered) = replace coer_offered dem_attr CT_Empty
# (off_coercions, coer_offered) = coer_offered![dem_attr]
(succ, off_coercions) = insert off_attr off_coercions
coer_offered = { coer_offered & [dem_attr] = off_coercions }
coer_offered = {coer_offered & [dem_attr] = off_coercions}
= {coer_demanded = coer_demanded, coer_offered = coer_offered}
= {coer_demanded = coer_demanded, coer_offered = coer_offered}
where
......@@ -716,9 +715,8 @@ makeUnique :: !Int !*Coercions -> *Coercions
makeUnique attr {coer_demanded, coer_offered}
# (off_coercions, coer_offered) = replace coer_offered attr CT_Empty
coer_demanded = { coer_demanded & [attr] = CT_Unique }
= make_unique off_coercions {coer_offered = coer_offered, coer_demanded = coer_demanded}// ---> ("makeUnique :", attr)
= make_unique off_coercions {coer_offered = coer_offered, coer_demanded = coer_demanded}
where
// JVG added type:
make_unique :: !CoercionTree !*Coercions -> *Coercions;
make_unique (CT_Node this_attr ct_less ct_greater) coercions
# coercions = makeUnique this_attr coercions
......@@ -989,7 +987,7 @@ copyCoercions coercions=:{coer_demanded, coer_offered}
= ({coercions & coer_demanded = coer_demanded, coer_offered = coer_offered}, {coercions & coer_demanded = coer_demanded_copy, coer_offered = coer_offered_copy})
where
copy_coercion_trees trees
= arrayAndElementsCopy CT_Empty copy_coercion_tree trees
= arrayAndElementsCopy copy_coercion_tree trees
copy_coercion_tree (CT_Node attr left right)
# (copy_left, left) = copy_coercion_tree left
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment