You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/PartitionStorage/FilePartitionsPresets.cs

38 lines
1.6 KiB

using System;
using ZeroLevel.Services.HashFunctions;
namespace ZeroLevel.Services.PartitionStorage
{
public static class FilePartitionsPresets
{
public static StoreFilePartition<string, TMeta> StringDivideIntoParts<TMeta>(string name, int parts)
{
Func<string, TMeta, string> extractor = (key, _) => ((int)Math.Abs(StringHash.DotNetFullHash(key) % parts)).ToString();
return new StoreFilePartition<string, TMeta>(name, extractor);
}
public static StoreFilePartition<ulong, TMeta> ULongDivideIntoParts<TMeta>(string name, int parts)
{
Func<ulong, TMeta, string> extractor = (key, _) => (key % (ulong)parts).ToString();
return new StoreFilePartition<ulong, TMeta>(name, extractor);
}
public static StoreFilePartition<long, TMeta> LongDivideIntoParts<TMeta>(string name, int parts)
{
Func<long, TMeta, string> extractor = (key, _) => (key % (long)parts).ToString();
return new StoreFilePartition<long, TMeta>(name, extractor);
}
public static StoreFilePartition<uint, TMeta> UIntDivideIntoParts<TMeta>(string name, int parts)
{
Func<uint, TMeta, string> extractor = (key, _) => (key % (uint)parts).ToString();
return new StoreFilePartition<uint, TMeta>(name, extractor);
}
public static StoreFilePartition<int, TMeta> IntDivideIntoParts<TMeta>(string name, int parts)
{
Func<int, TMeta, string> extractor = (key, _) => (key % parts).ToString();
return new StoreFilePartition<int, TMeta>(name, extractor);
}
}
}

Powered by TurnKey Linux.