private static Dictionary <int, List <string> > Partition(IEnumerable <string> xs, int numberOfPartitions = 10) { var partitions = new Dictionary <int, List <string> >(); for (var i = 0; i < numberOfPartitions; i++) { partitions.Add(i, new List <string>()); } foreach (string x in xs) { ulong idx = Fnv1Hash.Create(Encoding.ASCII.GetBytes(x)) % (ulong)partitions.Count; partitions[(int)idx].Add(x); } return(partitions); }
/// <summary> /// Writes collected schema to the stream and pops it. /// </summary> /// <param name="stream">The stream.</param> /// <param name="schemaOffset">The schema offset.</param> /// <param name="schemaId">The schema identifier.</param> /// <param name="flags">Flags according to offset sizes.</param> /// <returns> /// True if current schema was non empty; false otherwise. /// </returns> public bool WriteSchema(IBinaryStream stream, int schemaOffset, out int schemaId, ref BinaryObjectHeader.Flag flags) { schemaId = Fnv1Hash.Basis; var count = _idx - schemaOffset; if (count == 0) { return(false); } flags |= BinaryObjectHeader.WriteSchema(_fields, stream, schemaOffset, count); for (var i = schemaOffset; i < _idx; i++) { schemaId = Fnv1Hash.Update(schemaId, _fields[i].Id); } return(true); }