protected override IntersectState UpdateState(T key, IntersectState state, int updateRootIndex1, int updateRootIndex2)
        {
            var oldmin = Math.Min(state.val1, state.val2);

            // fold in new weight to the first value
            for (int i = updateRootIndex1; i >= 0; i = updateChain1[i].previous)
            {
                state.val1 += updateChain1[i].update.weight;
            }

            // fold in new weight to the first value
            for (int i = updateRootIndex2; i >= 0; i = updateChain2[i].previous)
            {
                state.val2 += updateChain2[i].update.weight;
            }

            var newmin = Math.Min(state.val1, state.val2);

            if (oldmin != newmin)
            {
                Send(new Weighted <T>(key, newmin - oldmin));
            }

            return(state);
        }
        public override void OnInput2(Weighted <T> input2)
        {
            IntersectState state;

            var key = input2.record;

            var present = states.TryGetValue(input2.record, out state);

            if (!present)
            {
                state = new IntersectState();
            }

            var oldmin = Math.Min(state.val1, state.val2);

            state.val2 += input2.weight;

            var newmin = Math.Min(state.val1, state.val2);

            if (oldmin != newmin)
            {
                Send(new Weighted <T>(key, newmin - oldmin));
            }

            if (state.val1 == 0.0 && state.val2 == 0.0)
            {
                if (present)
                {
                    states.Remove(key);
                }
            }
            else
            {
                if (!present)
                {
                    states.Add(key, state);
                }
                else
                {
                    states[key] = state;
                }
            }
        }
        protected override void UpdateState(Update update)
        {
            IntersectState state;

            var present = states.TryGetValue(update.key, out state);

            if (!present)
            {
                state = new IntersectState();
            }


            var oldmin = Math.Min(state.val1, state.val2);

            // fold in new weight to the first value
            for (int i = 0; i < update.inputs1.Count; i++)
            {
                state.val1 += update.inputs1.Array[i].weight;
            }

            // fold in new weight to the second value
            for (int i = 0; i < update.inputs2.Count; i++)
            {
                state.val2 += update.inputs2.Array[i].weight;
            }

            var newmin = Math.Min(state.val1, state.val2);

            if (oldmin != newmin)
            {
                Send(new Weighted <T>(update.key, newmin - oldmin));
            }


            if (!present)
            {
                states.Add(update.key, state);
            }
            else
            {
                states[update.key] = state;
            }
        }