/** Calculate single differences from two sets of observations. * Undifferenced input observations are assumed to be both taken at the * same time, `t`. * * SNR in the output is the lesser of the SNRs of inputs a and b. * * `sat_pos` and `sat_vel` are taken from input b. * * \param n_a Number of measurements in set `m_a` * \param m_a Array of undifferenced observations, as a set sorted by PRN * \param n_b Number of measurements in set `m_b` * \param m_b Array of undifferenced observations, as a set sorted by PRN * \param sds Single difference observations * * \return The number of observations written to `sds` on success, * -1 if `m_a` is not a valid set, * -2 if `m_b` is not a valid set */ u8 single_diff(u8 n_a, navigation_measurement_t *m_a, u8 n_b, navigation_measurement_t *m_b, sdiff_t *sds) { return intersection_map(n_a, sizeof(navigation_measurement_t), m_a, n_b, sizeof(navigation_measurement_t), m_b, nav_meas_cmp, sds, single_diff_); }
/** Take the intersection of two sets. * * Takes two arrays each representing a set and outputs two arrays containing * the elemnts from the input arrays that are equal under a comparison function * `cmp`. * * Set A and B should be represented as sorted arrays with no repeated * elements. * * \param na Number of elements in set A * \param sa Size of each element of set A * \param as Array of elements in set A * \param a_out Output array of matching elements from A * \param nb Number of elements in set B * \param sb Size of each element of set B * \param bs Array of elements in set B * \param b_out Output array of matching elements from B * \param cmp Pointer to a comparison function * * \return Number of elements in intersection on success, * -1 if A is not a valid set, * -2 if B is not a valid set */ s32 intersection(u32 na, size_t sa, const void *as, void *a_out, u32 nb, size_t sb, const void *bs, void *b_out, cmp_fn cmp) { struct intersection_context ctxt = { .a_out = a_out, .sa = sa, .b_out = b_out, .sb = sb }; return intersection_map(na, sa, as, nb, sb, bs, cmp, &ctxt, intersection_function); }