fn calculate_intersection()

in protocol/src/cross_psi/company.rs [272:315]


    fn calculate_intersection(&self, keys: TPayload) {
        let partner_keys = self.ec_cipher.to_bytes(
            &self
                .ec_cipher
                .to_points_encrypt(keys.as_slice(), &self.ec_key),
        );

        // find the index of the intersection

        if let (Ok(company_keys), Ok(mut partner_mask), Ok(mut company_indices)) = (
            self.encrypted_company_keys.clone().read(),
            self.partner_intersection_mask.clone().write(),
            self.self_intersection_indices.clone().write(),
        ) {
            if company_keys.is_empty() {
                panic!("e_partner keys should be uploaded after e_company keys are uploaded");
            }

            partner_mask.clear();

            partner_mask.extend(common::vectors::vec_intersection_mask(
                partner_keys.as_slice(),
                company_keys.as_slice(),
            ));

            // TODO: can this be a parallel forall
            for (flag, partner_key) in partner_mask.iter().zip(&partner_keys) {
                if *flag {
                    let index = company_keys
                        .iter()
                        .position(|x| *x == *partner_key)
                        .unwrap();
                    company_indices.push(index);
                }
            }

            info!(
                "Company-Partner Intersection size: {}",
                company_indices.len()
            );
        } else {
            panic!("Unable to find interesection");
        }
    }