writeClientsStructs = (encoder, store, _sm) => {
  // we filter all valid _sm entries into sm
  const sm = new Map();

  _sm.forEach((clock, client) => {
    // only write if new structs are available
    if (getState(store, client) > clock) {
      sm.set(client, clock);
    }
  });

  getStateVector(store).forEach((clock, client) => {
    if (!_sm.has(client)) {
      sm.set(client, 0);
    }
  }); // write # states that were updated

  encoding.writeVarUint(encoder.restEncoder, sm.size); // Write items with higher client ids first
  // This heavily improves the conflict algorithm.

  Array.from(sm.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {
    // @ts-ignore
    writeStructs(encoder, store.clients.get(client), client, clock);
  });
}
@param {UpdateEncoderV1 | UpdateEncoderV2} encoder
@param {StructStore} store
@param {Map<number,number>} _sm

@private
@function