时间:2019-03-07 标签:c#cube/multiDimensionalDataset

发布于 2024-08-23 17:57:41 字数 287 浏览 7 评论 0原文

我正在解决一个问题,我需要使用 C# 处理内存中的多维数据。我的需求类似于 OLAP 多维数据集,但没有那么复杂。例如,我不需要计算或聚合或类似的东西。我基本上想使用多维键引用数据。例如:

var key = new Key();
key["Dim1"] = "DimValue1";
key["Dim2"] = "DimValue2";
key["Time"] = 1999;
DataSet[key] = 4.43434m;

它允许我迭代数据集的值或切片。你在 C# 中遇到过这样的库吗?

I'm working on a problem where i need to process multi dimensional data in memory using C#. My requirement resemble OLAP cubes but are not as complex. for example i don't need calculations or aggregation or stuff like that. I basically would like to reference data using multidimensional keys. for example:

var key = new Key();
key["Dim1"] = "DimValue1";
key["Dim2"] = "DimValue2";
key["Time"] = 1999;
DataSet[key] = 4.43434m;

And it would allow me to iterate on the values or slices of the dataset. Have you come across such a library in C#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

像你 2024-08-30 17:57:41

这可能无法满足您的需求,但我发现处理多键数据集的一种简单方法是创建一个包含所有“键”字段和“值”键(根据您需要的数量)的对象,并且然后为每个键创建查找表达式。

例如:

class MyData
{
    // Your keys
    public string Dim1;
    public string Dim2;
    public string Time;

    // Your values
    public string Value;
}

将被“索引”并像这样检索:

// add all your data to a list or collection
var data = new List<MyData>();

// this provides the entry point to our dataset
var lookupDim1 = data.ToLookup(d => d.Dim1);
var lookupDim2 = data.ToLookup(d => d.Dim2);
var lookupTime = data.ToLookup(d => d.Time);

// sample retrievals
IEnumerable<MyData> sampleData1 = lookupDim1["DimValue1"];
var sampleData2 = lookupDim2["DimValue2"].Intersect( lookupTime["1999"] );

This may not meet your need, but I've found a simple way to deal with multi-key datasets is to create an object which contains all your 'key' fields and 'value' keys (as many of each as you need) and then create Lookup expressions for each of your keys.

For example:

class MyData
{
    // Your keys
    public string Dim1;
    public string Dim2;
    public string Time;

    // Your values
    public string Value;
}

would be 'indexed' and retrieved like this:

// add all your data to a list or collection
var data = new List<MyData>();

// this provides the entry point to our dataset
var lookupDim1 = data.ToLookup(d => d.Dim1);
var lookupDim2 = data.ToLookup(d => d.Dim2);
var lookupTime = data.ToLookup(d => d.Time);

// sample retrievals
IEnumerable<MyData> sampleData1 = lookupDim1["DimValue1"];
var sampleData2 = lookupDim2["DimValue2"].Intersect( lookupTime["1999"] );
祁梦 2024-08-30 17:57:41

您可以创建一个字典,其中键类型是您声明的结构。尽管您可以通过过滤来实现切片的自动迭代,但它不会为您提供切片的自动迭代。

You could create a dictionary where the key type is a struct that you declare. That doesn't give you automatic iteration of slices, although you could achieve it by filtering.

贪了杯 2024-08-30 17:57:41

我认为像 MongoDB 和 Redis 这样的键/值存储很接近我的需要。不过我不是100%确定。由于我不关心持久性,因此像 Redis 这样的内存故事更合适。

I think a key/value store like MongoDB and Redis is close to what I need. However I'm not 100% sure. Since I don't care about persistence, in memory story like Redis is more suitable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文