Skip to content

Commit 824fe20

Browse files
committed
update
1 parent 3e6f96b commit 824fe20

24 files changed

+449
-93
lines changed

dolphindb_csharpapi/data/AbstractVector.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ public virtual object getList()
9797
throw new NotImplementedException();
9898
}
9999

100+
100101
public abstract void set(int index, string value);
102+
public abstract void add(object value);
103+
public abstract void addRange(object list);
101104
}
102105

103106
}

dolphindb_csharpapi/data/BasicAnyVector.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public override void set(int index, string value)
127127
{
128128
values[index] = new BasicString(value);
129129
}
130+
131+
public override void add(object value)
132+
{
133+
throw new NotImplementedException();
134+
}
135+
136+
public override void addRange(object list)
137+
{
138+
throw new NotImplementedException();
139+
}
130140
}
131141

132142
}

dolphindb_csharpapi/data/BasicBooleanVector.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using dolphindb.io;
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
namespace dolphindb.data
67
{
78

89

910
public class BasicBooleanVector : AbstractVector
1011
{
11-
private byte[] values;
12+
private List<byte> values;
1213

1314
public BasicBooleanVector(int size) : this(DATA_FORM.DF_VECTOR, size)
1415
{
@@ -18,30 +19,36 @@ public BasicBooleanVector(IList<byte?> list) : base(DATA_FORM.DF_VECTOR)
1819
{
1920
if (list != null)
2021
{
21-
values = new byte[list.Count];
22-
for (int i = 0; i < list.Count; ++i)
23-
{
24-
values[i] = list[i].Value;
25-
}
22+
values = list.Where(x => x != null).Cast<byte>().ToList();
23+
//values = new byte[list.Count];
24+
//for (int i = 0; i < list.Count; ++i)
25+
//{
26+
// values[i] = list[i].Value;
27+
//}
2628
}
2729
}
2830

2931
public BasicBooleanVector(byte[] array) : base(DATA_FORM.DF_VECTOR)
3032
{
31-
values = array.Clone() as byte[];
33+
values = new List<byte>(array.Length);
34+
values.AddRange(array);
35+
//array.Clone() as byte[];
3236
}
3337

3438
protected internal BasicBooleanVector(DATA_FORM df, int size) : base(df)
3539
{
36-
values = new byte[size];
40+
41+
values = new List<byte>(size);
42+
values.AddRange(new byte[size]);
3743
}
3844

3945
protected internal BasicBooleanVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
4046
{
4147
int rows = @in.readInt();
4248
int cols = @in.readInt();
4349
int size = rows * cols;
44-
values = new byte[size];
50+
values = new List<byte>(size);
51+
values.AddRange(new byte[size]);
4552
for (int i = 0; i < size; ++i)
4653
{
4754
values[i] = @in.readByte();
@@ -100,12 +107,12 @@ public override Type getElementClass()
100107

101108
public override int rows()
102109
{
103-
return values.Length;
110+
return values.Count;
104111
}
105112

106113
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out)
107114
{
108-
@out.write(values);
115+
@out.write(values.ToArray());
109116
}
110117

111118
public override void set(int index, string value)
@@ -120,6 +127,17 @@ public override void set(int index, string value)
120127
setNull(index);
121128
}
122129
}
130+
131+
public override void add(object value)
132+
{
133+
values.Add(Convert.ToByte(value));
134+
}
135+
136+
public override void addRange(object list)
137+
{
138+
List<byte> data = (List<byte>)list;
139+
values.AddRange(data);
140+
}
123141
}
124142

125143
}

dolphindb_csharpapi/data/BasicByteVector.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using dolphindb.io;
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
namespace dolphindb.data
67
{
78
public class BasicByteVector : AbstractVector
89
{
9-
private byte[] values;
10+
private List<byte> values;
1011

1112
public BasicByteVector(int size) : this(DATA_FORM.DF_VECTOR, size)
1213
{
@@ -16,30 +17,36 @@ public BasicByteVector(IList<byte?> list) : base(DATA_FORM.DF_VECTOR)
1617
{
1718
if (list != null)
1819
{
19-
values = new byte[list.Count];
20-
for (int i = 0; i < list.Count; ++i)
21-
{
22-
values[i] = list[i].Value;
23-
}
20+
values = list.Where(x => x != null).Cast<byte>().ToList();
21+
//values = new byte[list.Count];
22+
//for (int i = 0; i < list.Count; ++i)
23+
//{
24+
// values[i] = list[i].Value;
25+
//}
2426
}
2527
}
2628

2729
public BasicByteVector(byte[] array) : base(DATA_FORM.DF_VECTOR)
2830
{
29-
values = array.Clone() as byte[];
31+
values = new List<byte>(array.Length);
32+
values.AddRange(array);
33+
//values = array.Clone() as byte[];
3034
}
3135

3236
protected internal BasicByteVector(DATA_FORM df, int size) : base(df)
3337
{
34-
values = new byte[size];
38+
39+
values = new List<byte>(size);
40+
values.AddRange(new byte[size]);
3541
}
3642

3743
protected internal BasicByteVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
3844
{
3945
int rows = @in.readInt();
4046
int cols = @in.readInt();
4147
int size = rows * cols;
42-
values = new byte[size];
48+
values = new List<byte>(size);
49+
values.AddRange(new byte[size]);
4350
for (int i = 0; i < size; ++i)
4451
{
4552
values[i] = @in.readByte();
@@ -101,12 +108,12 @@ public override Type getElementClass()
101108

102109
public override int rows()
103110
{
104-
return values.Length;
111+
return values.Count;
105112
}
106113

107114
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out)
108115
{
109-
@out.write(values);
116+
@out.write(values.ToArray());
110117
}
111118

112119
public override object getList()
@@ -126,6 +133,17 @@ public override void set(int index, string value)
126133
setNull(index);
127134
}
128135
}
136+
137+
public override void add(object value)
138+
{
139+
values.Add(Convert.ToByte(value));
140+
}
141+
142+
public override void addRange(object list)
143+
{
144+
List<byte> data = (List<byte>)list;
145+
values.AddRange(data);
146+
}
129147
}
130148

131149
}

dolphindb_csharpapi/data/BasicDate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public override void setObject(object value)
8686
base.setObject(Utils.countDays(Convert.ToDateTime(value)));
8787
}
8888
}
89+
8990
}
9091

9192
}

dolphindb_csharpapi/data/BasicDateTimeVector.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ public override void set(int index, string value)
8686
}
8787
base.set(index, value);
8888
}
89+
90+
public override void add(object value)
91+
{
92+
if (value is DateTime)
93+
{
94+
base.add(Utils.countSeconds((DateTime)value));
95+
}
96+
else if (value is String)
97+
{
98+
DateTime dtm = new DateTime();
99+
if (DateTime.TryParse(value.ToString(), out dtm))
100+
{
101+
base.add(Utils.countSeconds(dtm));
102+
return;
103+
}
104+
}
105+
106+
}
89107
}
90108

91109
}

dolphindb_csharpapi/data/BasicDateVector.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ public override void set(int index, string value)
7575
base.set(index, value);
7676
}
7777

78+
public override void add(object value)
79+
{
80+
if(value is DateTime)
81+
{
82+
base.add(Utils.countDays((DateTime)value));
83+
}
84+
else if (value is String)
85+
{
86+
DateTime dtm = new DateTime();
87+
if (DateTime.TryParse(value.ToString(), out dtm))
88+
{
89+
base.add(Utils.countDays(dtm));
90+
return;
91+
}
92+
}
93+
94+
}
7895
}
7996

8097
}

dolphindb_csharpapi/data/BasicDoubleVector.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace dolphindb.data
66
{
77
public class BasicDoubleVector : AbstractVector
88
{
9-
private double[] values;
9+
private List<double> values;
1010

1111
public BasicDoubleVector(int size) : this(DATA_FORM.DF_VECTOR, size)
1212
{
@@ -16,30 +16,35 @@ public BasicDoubleVector(IList<double?> list) : base(DATA_FORM.DF_VECTOR)
1616
{
1717
if (list != null)
1818
{
19-
values = new double[list.Count];
20-
for (int i = 0; i < list.Count; ++i)
21-
{
22-
values[i] = list[i].Value;
23-
}
19+
values = list.Where(x => x != null).Cast<double>().ToList();
20+
//values = new double[list.Count];
21+
//for (int i = 0; i < list.Count; ++i)
22+
//{
23+
// values[i] = list[i].Value;
24+
//}
2425
}
2526
}
2627

2728
public BasicDoubleVector(double[] array) : base(DATA_FORM.DF_VECTOR)
2829
{
29-
values = array.Clone() as double[];
30+
values = new List<double>(array.Length);
31+
values.AddRange(array);
32+
//values = array.Clone() as double[];
3033
}
3134

3235
protected internal BasicDoubleVector(DATA_FORM df, int size) : base(df)
3336
{
34-
values = new double[size];
37+
values = new List<double>(size);
38+
values.AddRange(new double[size]);
3539
}
3640

3741
protected internal BasicDoubleVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
3842
{
3943
int rows = @in.readInt();
4044
int cols = @in.readInt();
4145
int size = rows * cols;
42-
values = new double[size];
46+
values = new List<double>(size);
47+
values.AddRange(new double[size]);
4348
for (int i = 0; i < size; ++i)
4449
{
4550
values[i] = @in.readDouble();
@@ -97,12 +102,12 @@ public override Type getElementClass()
97102

98103
public override int rows()
99104
{
100-
return values.Length;
105+
return values.Count;
101106
}
102107

103108
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out)
104109
{
105-
@out.writeDoubleArray(values);
110+
@out.writeDoubleArray(values.ToArray());
106111
}
107112

108113
public override object getList()
@@ -122,5 +127,16 @@ public override void set(int index, string value)
122127
setNull(index);
123128
}
124129
}
130+
131+
public override void add(object value)
132+
{
133+
values.Add(Convert.ToDouble(value));
134+
}
135+
136+
public override void addRange(object list)
137+
{
138+
List<double> data = (List<double>)list;
139+
values.AddRange(data);
140+
}
125141
}
126142
}

0 commit comments

Comments
 (0)