支持各种数据类型的数据结构

时间:2017-10-04 21:15:30

标签: database data-structures

假设我有一个如下数据集:

Seq1 | Seq2 | Seq3 |疾病|年龄

====================================

A | T | G |发烧,咳嗽| 24

T | C | G |高血压| 56

C | T | A |糖尿病,高血压| 79

我应该选择哪种数据结构支持字母数据{A / T / C / G},集值数据{糖尿病,高血压}和数字数据{年龄}?

如果我有一个coount查询,例如:seq2 = T,疾病='高血压',年龄> 50 ==>答案应该是2.

我想知道我应该使用什么样的数据结构来有效地适应所有类型的数据和上述查询?或者我是否需要构建3个数据结构然后将结果相交?

2 个答案:

答案 0 :(得分:0)

如果您使用的是OOP语言,请考虑创建一个包含所需属性的类(Seq 1,Seq 2,Seq 3,症状列表,Age)。然后,您可以实例化该类,并将生成的对象放入各种数据结构(如列表)。

答案 1 :(得分:0)

一个类应该是处理这个结构的正确方法,C#中的一个简单实现看起来像这样:

using System.Collections.Generic;

namespace DataStructure
{
    class Program
    {
        static void Main(string[] args)
        {
            // Creating Data Set
            var AllDataSet = new List<DataStructure>();
            AllDataSet.Add(
                new DataStructure(new char[] { 'A', 'T', 'G' }, new string[] { "Fever", "Cough" }, 24)           
            );

            AllDataSet.Add(
                new DataStructure(new char[] { 'T', 'C', 'G' }, new string[] { "High Blood Pressure" }, 56)
            );

            AllDataSet.Add(
                new DataStructure(new char[] { 'A', 'T', 'G' }, new string[] { "Diabetes", "High Blood Pressure" }, 79)
            );
        }
    }

    public class DataStructure
    {
        public char[] DNAChar;
        public string[] SetValuedData;
        public int Age;

        public DataStructure(char[] dnaChar, string[] setValuedData, int age)
        {
            DNAChar = dnaChar;
            SetValuedData = setValuedData;
            Age = age;
        }

        // Add other logic here
    }
}

然后您可以添加功能来实现您的逻辑。希望,这会有所帮助!