/// <summary> /// Creates a new correlation vector by applying the Spin operator to an existing value. /// This should be done at the entry point of an operation. /// </summary> /// <param name="correlationVector"> /// Taken from the message header indicated by <see cref="HeaderName"/>. /// </param> /// <param name="parameters"> /// The parameters to use when applying the Spin operator. /// </param> /// <returns>A new correlation vector extended from the current vector.</returns> public new static CorrelationVectorV2 Spin(string correlationVector, SpinParameters parameters) { if (CorrelationVectorV2.IsImmutable(correlationVector)) { return(CorrelationVectorV2.Parse(correlationVector)); } if (CorrelationVectorV2.ValidateCorrelationVectorDuringCreation) { CorrelationVectorV2.Validate(correlationVector); } byte[] entropy = new byte[parameters.EntropyBytes]; rng.NextBytes(entropy); ulong value = (ulong)(DateTime.UtcNow.Ticks >> parameters.TicksBitsToDrop); for (int i = 0; i < parameters.EntropyBytes; i++) { value = (value << 8) | Convert.ToUInt64(entropy[i]); } // Generate a bitmask and mask the lower TotalBits in the value. // The mask is generated by (1 << TotalBits) - 1. We need to handle the edge case // when shifting 64 bits, as it wraps around. value &= (parameters.TotalBits == 64 ? 0 : (ulong)1 << parameters.TotalBits) - 1; string s = unchecked ((uint)value).ToString(); if (parameters.TotalBits > 32) { s = string.Concat((value >> 32).ToString(), ".", s); } string baseVector = string.Concat(correlationVector, ".", s); if (CorrelationVectorV2.IsOversized(baseVector, 0)) { return(CorrelationVectorV2.Parse(correlationVector + CorrelationVectorV2.TerminationSign)); } return(new CorrelationVectorV2(baseVector, 0, false)); }
/// <summary> /// Creates a new correlation vector by extending an existing value. This should be /// done at the entry point of an operation. /// </summary> /// <param name="correlationVector"> /// Taken from the message header indicated by <see cref="HeaderName"/>. /// </param> /// <returns>A new correlation vector extended from the current vector.</returns> public new static CorrelationVectorV2 Extend(string correlationVector) { if (CorrelationVectorV2.IsImmutable(correlationVector)) { return(CorrelationVectorV2.Parse(correlationVector)); } if (CorrelationVectorV2.ValidateCorrelationVectorDuringCreation) { CorrelationVectorV2.Validate(correlationVector); } if (CorrelationVectorV2.IsOversized(correlationVector, 0)) { return(CorrelationVectorV2.Parse(correlationVector + CorrelationVectorV2.TerminationSign)); } return(new CorrelationVectorV2(correlationVector, 0, false)); }