@@ -2024,7 +2024,13 @@ pub fn aggregate_bottom_remove(current: &mut AggregateEntry, params: &Vec<Intern
20242024}
20252025
20262026pub fn aggregate_next_add ( current : & mut AggregateEntry , params : & Vec < Internable > , _: & Vec < Internable > ) {
2027- if let & mut AggregateEntry :: Sorted { ref mut items, current_round, ref current_params, ref mut changes, ..} = current {
2027+ if let & mut AggregateEntry :: Sorted { ref mut items, current_round, input_round, ref current_params, ref mut changes, ..} = current {
2028+ if let Some ( counts) = items. get ( params) {
2029+ let sum: Count = counts. iter ( ) . filter ( |cur| cur. abs ( ) <= current_round as i32 ) . map ( |& cur| if cur < 0 { -1 } else { 1 } ) . sum ( ) ;
2030+ if sum < 0 {
2031+ return ;
2032+ }
2033+ }
20282034 if let & Some ( _) = current_params {
20292035 let prev = items. range :: < Vec < Internable > , _ > ( ( Bound :: Unbounded , Bound :: Excluded ( params) ) )
20302036 . rev ( )
@@ -2034,29 +2040,42 @@ pub fn aggregate_next_add(current: &mut AggregateEntry, params: &Vec<Internable>
20342040 . filter ( |entry| is_aggregate_in_round ( entry, current_round) )
20352041 . next ( ) ;
20362042 match prev {
2037- Some ( ( v, _) ) => {
2038- let mut neue = v. clone ( ) ;
2039- neue. extend ( params. iter ( ) . cloned ( ) ) ;
2040- changes. push ( ( neue, current_round, 1 ) ) ;
2041- if let Some ( ( prev_next, _) ) = next {
2043+ Some ( ( v, prev_rounds) ) => {
2044+ let mut do_it = current_round == input_round ||
2045+ prev_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) . is_some ( ) ;
2046+ if do_it {
20422047 let mut neue = v. clone ( ) ;
2043- neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2044- changes. push ( ( neue, current_round, -1 ) ) ;
2048+ neue. extend ( params. iter ( ) . cloned ( ) ) ;
2049+ changes. push ( ( neue, current_round, 1 ) ) ;
2050+ }
2051+
2052+ if let Some ( ( prev_next, prev_next_rounds) ) = next {
2053+ do_it = do_it ||
2054+ prev_next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) . is_some ( ) ;
2055+ if do_it {
2056+ let mut neue = v. clone ( ) ;
2057+ neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2058+ changes. push ( ( neue, current_round, -1 ) ) ;
2059+ }
20452060 }
20462061 }
20472062 _ => { }
20482063 }
2049- if let Some ( ( params_next, _) ) = next {
2050- let mut neue = params. clone ( ) ;
2051- neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2052- changes. push ( ( neue, current_round, 1 ) ) ;
2064+ if let Some ( ( params_next, next_rounds) ) = next {
2065+ let do_it = current_round == input_round ||
2066+ next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) . is_some ( ) ;
2067+ if do_it {
2068+ let mut neue = params. clone ( ) ;
2069+ neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2070+ changes. push ( ( neue, current_round, 1 ) ) ;
2071+ }
20532072 }
20542073 }
20552074 }
20562075}
20572076
20582077pub fn aggregate_next_remove ( current : & mut AggregateEntry , params : & Vec < Internable > , _: & Vec < Internable > ) {
2059- if let & mut AggregateEntry :: Sorted { ref mut items, current_round, ref current_params, ref mut changes, ..} = current {
2078+ if let & mut AggregateEntry :: Sorted { ref mut items, current_round, input_round , ref current_params, ref mut changes, ..} = current {
20602079 if let & Some ( _) = current_params {
20612080 let prev = items. range :: < Vec < Internable > , _ > ( ( Bound :: Unbounded , Bound :: Excluded ( params) ) )
20622081 . rev ( )
@@ -2066,29 +2085,48 @@ pub fn aggregate_next_remove(current: &mut AggregateEntry, params: &Vec<Internab
20662085 . filter ( |entry| is_aggregate_in_round ( entry, current_round) )
20672086 . next ( ) ;
20682087 match prev {
2069- Some ( ( v, _) ) => {
2070- let mut neue = v. clone ( ) ;
2071- neue. extend ( params. iter ( ) . cloned ( ) ) ;
2072- changes. push ( ( neue, current_round, -1 ) ) ;
2073- if let Some ( ( prev_next, _) ) = next {
2088+ Some ( ( v, prev_rounds) ) => {
2089+ let interesting = prev_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) ;
2090+ let mut do_it = current_round == input_round || interesting. is_some ( ) ;
2091+ if do_it {
20742092 let mut neue = v. clone ( ) ;
2075- neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2076- changes. push ( ( neue, current_round, 1 ) ) ;
2093+ neue. extend ( params. iter ( ) . cloned ( ) ) ;
2094+ changes. push ( ( neue, current_round, -1 ) ) ;
2095+ }
2096+
2097+ if let Some ( ( prev_next, prev_next_rounds) ) = next {
2098+ let interesting = prev_next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) ;
2099+ do_it = do_it || interesting. is_some ( ) ;
2100+ if do_it {
2101+ let mut neue = v. clone ( ) ;
2102+ neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2103+ changes. push ( ( neue, current_round, 1 ) ) ;
2104+ }
20772105 }
20782106 }
20792107 _ => { }
20802108 }
2081- if let Some ( ( params_next, _) ) = next {
2082- let mut neue = params. clone ( ) ;
2083- neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2084- changes. push ( ( neue, current_round, -1 ) ) ;
2109+ if let Some ( ( params_next, next_rounds) ) = next {
2110+ let do_it = current_round == input_round ||
2111+ next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) . is_some ( ) ;
2112+ if do_it {
2113+ let mut neue = params. clone ( ) ;
2114+ neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2115+ changes. push ( ( neue, current_round, -1 ) ) ;
2116+ }
20852117 }
20862118 }
20872119 }
20882120}
20892121
20902122pub fn aggregate_prev_add ( current : & mut AggregateEntry , params : & Vec < Internable > , _: & Vec < Internable > ) {
2091- if let & mut AggregateEntry :: Sorted { ref mut items, current_round, ref current_params, ref mut changes, ..} = current {
2123+ if let & mut AggregateEntry :: Sorted { ref mut items, current_round, input_round, ref current_params, ref mut changes, ..} = current {
2124+ if let Some ( counts) = items. get ( params) {
2125+ let sum: Count = counts. iter ( ) . filter ( |cur| cur. abs ( ) <= current_round as i32 ) . map ( |& cur| if cur < 0 { -1 } else { 1 } ) . sum ( ) ;
2126+ if sum < 0 {
2127+ return ;
2128+ }
2129+ }
20922130 if let & Some ( _) = current_params {
20932131 let next = items. range :: < Vec < Internable > , _ > ( ( Bound :: Unbounded , Bound :: Excluded ( params) ) )
20942132 . rev ( )
@@ -2098,29 +2136,42 @@ pub fn aggregate_prev_add(current: &mut AggregateEntry, params: &Vec<Internable>
20982136 . filter ( |entry| is_aggregate_in_round ( entry, current_round) )
20992137 . next ( ) ;
21002138 match prev {
2101- Some ( ( v, _) ) => {
2102- let mut neue = v. clone ( ) ;
2103- neue. extend ( params. iter ( ) . cloned ( ) ) ;
2104- changes. push ( ( neue, current_round, 1 ) ) ;
2105- if let Some ( ( prev_next, _) ) = next {
2139+ Some ( ( v, prev_rounds) ) => {
2140+ let interesting = prev_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) ;
2141+ let mut do_it = current_round == input_round || interesting. is_some ( ) ;
2142+ if do_it {
21062143 let mut neue = v. clone ( ) ;
2107- neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2108- changes. push ( ( neue, current_round, -1 ) ) ;
2144+ neue. extend ( params. iter ( ) . cloned ( ) ) ;
2145+ changes. push ( ( neue, current_round, 1 ) ) ;
2146+ }
2147+
2148+ if let Some ( ( prev_next, prev_next_rounds) ) = next {
2149+ let interesting = prev_next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) ;
2150+ do_it = do_it || interesting. is_some ( ) ;
2151+ if do_it {
2152+ let mut neue = v. clone ( ) ;
2153+ neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2154+ changes. push ( ( neue, current_round, -1 ) ) ;
2155+ }
21092156 }
21102157 }
21112158 _ => { }
21122159 }
2113- if let Some ( ( params_next, _) ) = next {
2114- let mut neue = params. clone ( ) ;
2115- neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2116- changes. push ( ( neue, current_round, 1 ) ) ;
2160+ if let Some ( ( params_next, next_rounds) ) = next {
2161+ let do_it = current_round == input_round ||
2162+ next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) . is_some ( ) ;
2163+ if do_it {
2164+ let mut neue = params. clone ( ) ;
2165+ neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2166+ changes. push ( ( neue, current_round, 1 ) ) ;
2167+ }
21172168 }
21182169 }
21192170 }
21202171}
21212172
21222173pub fn aggregate_prev_remove ( current : & mut AggregateEntry , params : & Vec < Internable > , _: & Vec < Internable > ) {
2123- if let & mut AggregateEntry :: Sorted { ref mut items, current_round, ref current_params, ref mut changes, ..} = current {
2174+ if let & mut AggregateEntry :: Sorted { ref mut items, current_round, input_round , ref current_params, ref mut changes, ..} = current {
21242175 if let & Some ( _) = current_params {
21252176 let next = items. range :: < Vec < Internable > , _ > ( ( Bound :: Unbounded , Bound :: Excluded ( params) ) )
21262177 . rev ( )
@@ -2130,22 +2181,35 @@ pub fn aggregate_prev_remove(current: &mut AggregateEntry, params: &Vec<Internab
21302181 . filter ( |entry| is_aggregate_in_round ( entry, current_round) )
21312182 . next ( ) ;
21322183 match prev {
2133- Some ( ( v, _) ) => {
2134- let mut neue = v. clone ( ) ;
2135- neue. extend ( params. iter ( ) . cloned ( ) ) ;
2136- changes. push ( ( neue, current_round, -1 ) ) ;
2137- if let Some ( ( prev_next, _) ) = next {
2184+ Some ( ( v, prev_rounds) ) => {
2185+ let interesting = prev_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) ;
2186+ let mut do_it = current_round == input_round || interesting. is_some ( ) ;
2187+ if do_it {
21382188 let mut neue = v. clone ( ) ;
2139- neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2140- changes. push ( ( neue, current_round, 1 ) ) ;
2189+ neue. extend ( params. iter ( ) . cloned ( ) ) ;
2190+ changes. push ( ( neue, current_round, -1 ) ) ;
2191+ }
2192+
2193+ if let Some ( ( prev_next, prev_next_rounds) ) = next {
2194+ let interesting = prev_next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) ;
2195+ do_it = do_it || interesting. is_some ( ) ;
2196+ if do_it {
2197+ let mut neue = v. clone ( ) ;
2198+ neue. extend ( prev_next. iter ( ) . cloned ( ) ) ;
2199+ changes. push ( ( neue, current_round, 1 ) ) ;
2200+ }
21412201 }
21422202 }
21432203 _ => { }
21442204 }
2145- if let Some ( ( params_next, _) ) = next {
2146- let mut neue = params. clone ( ) ;
2147- neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2148- changes. push ( ( neue, current_round, -1 ) ) ;
2205+ if let Some ( ( params_next, next_rounds) ) = next {
2206+ let do_it = current_round == input_round ||
2207+ next_rounds. iter ( ) . find ( |& c| * c == current_round as i32 ) . is_some ( ) ;
2208+ if do_it {
2209+ let mut neue = params. clone ( ) ;
2210+ neue. extend ( params_next. iter ( ) . cloned ( ) ) ;
2211+ changes. push ( ( neue, current_round, -1 ) ) ;
2212+ }
21492213 }
21502214 }
21512215 }
@@ -2855,7 +2919,7 @@ fn transaction_flow_meta(commits: &mut Vec<Change>, frame: &mut Frame, iter_pool
28552919 while current_round <= max_round {
28562920 let round = items. get_round ( & mut program. state . rounds , current_round) ;
28572921 for change in round. iter ( ) {
2858- // println!("{}", change.print(&program.state.interner));
2922+ // println!("-> {}", change.print(&program.state.interner));
28592923 // If this is an add, we want to do it *before* we start running pipes.
28602924 // This ensures that if there are two constraints in a single block that
28612925 // would both match the given input, they both have a chance to see this
0 commit comments