-- utilities for energy flow processing -- John Ringland 2005/08/27 with trace include misc.e -- for the pretty_print function --include SparseSM.e -- for sparse system matrices --without type_check --with profile_time --with profile -- some constants to make the data accessing more human readable -- -- System Model components global constant model_ = 1 global constant ST_ = 1 -- operator list global constant SM_ = 2 -- system matrix global constant SV_ = 3 -- state vector global constant CU_ = 4 -- update list --global constant MD_ = 4 global function union_SET(sequence set1, sequence set2) -- set1 and set2 are ordered lists of atoms with no duplicates -- this function performs the operation of the Union of the two sets by adding the -- elements of the smallest set to to the largest set if they are not already present. -- It takes advantage of the ordering of the sets to optimise the procedure. sequence result, set, data integer rId, slen1, slen2, slen, dlen rId = 1 slen1 = length(set1) slen2 = length(set2) if slen1 < slen2 then -- so that we iterate over the smallest set for efficiency data = set1 set = set2 slen = slen2 dlen = slen1 else data = set2 set = set1 slen = slen1 dlen = slen2 end if for i = 1 to dlen do -- uses rId so we search only that part of the set that the datum may be in -- this is possible because of the ordering of both sets. if rId > slen then set = set & data[i..dlen] exit end if result = BSearch(set[rId..slen],data[i]) rId += result[index_]-1 if not result[found_] then -- insert data[i] -- if new head if rId = 0 then set = {data[i]} & set slen += 1 rId += 2 -- if tail elsif rId = slen then -- because data is ordered the remainder can be appended set = set & data[i..dlen] exit -- if body else set = set[1..rId] & {data[i]} & set[rId+1..slen] slen += 1 rId += 2 end if else -- data[i] already in set rId += 1 end if end for return set end function global procedure print_sv(sequence sv, sequence sv_names) for i = 1 to length(sv) do puts(1,"\n# ") puts(1, sv_names[i]) puts(1, " #####\n") pretty_print(1,sv[i],{}) end for end procedure