public IEnumerable <Observation> Aggregate(IPartitioner partitioner, ICalculator calculator) { var partitions = partitioner.Partition(_observations); foreach (var partition in partitions) { yield return(calculator.AggregateCollection(partition)); } }
private Partition CallCustomPartitioner(string topic, IPartitioner partitioner, IntPtr keydata, UIntPtr keylen, int partition_cnt, IntPtr rkt_opaque, IntPtr msg_opaque) { try { return(partitioner.Partition(topic, keydata, keylen, partition_cnt, rkt_opaque, msg_opaque)); } catch { return(Partition.Any); } }
public override int SelectChannel(SerializationDelegate <StreamRecord <TData> > record) { TKey key; try { key = keySelector.GetKey(record.Instance.Value); } catch (Exception e) { throw new RuntimeException($"Could not extract key from {record.Instance}", e); } return(partitioner.Partition(key, NumberOfChannels)); }
public IEnumerable <IPartition> PartitionModel(IModel model) { IEnumerable <ISuperNode> coarsenedGraph = this.coarsener.Coarsen(model.Nodes); OnAfterCoarsening(coarsenedGraph); IEnumerable <IPartition> partitions = partitioner.Partition(coarsenedGraph); OnAfterPartitioning(partitions); // uncoarsen and refine partitions in place this.coarsener.Uncoarsen(partitions, this.refiner); return(partitions); }
public void QuickSort(int[] arr, int low, int high) { /* Partitioning schemes * Always pick first element as pivot. * Always pick last element as pivot * Pick a random element as pivot. * Pick median as pivot. */ // pick the first element as pivot if (low < high) { var index = _partitionImpl.Partition(arr, low, high); QuickSort(arr, low, index); QuickSort(arr, index + 1, high); } }
private int GetPartition(TK key, bool isKeyNull, int numPartitions) { if (numPartitions <= 0) { throw new InvalidPartitionException( string.Format("Invalid number of partitions: {0}. Valid values are > 0", numPartitions)); } //TODO: In java version, if key is null, will cache one partition for the topic. var partition = key == null || isKeyNull ? random.Next(numPartitions) : partitioner.Partition(key, numPartitions); if (partition < 0 || partition >= numPartitions) { throw new InvalidPartitionException( string.Format("Invalid partition id : {0}. Valid values are in the range inclusive [0, {1}]", partition, numPartitions - 1)); } return(partition); }