Skip to content

Commit e82bad7

Browse files
committed
Add skeleton for Array
Signed-off-by: Yue Yin <[email protected]>
1 parent 7e64a59 commit e82bad7

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

docs/src/01-04-array.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,71 @@ DataChunk 是数据库执行引擎中对数据处理的基本单位。对于大
108108

109109
## 整体设计
110110

111-
一种可供参考的接口设计:
111+
一种可供参考的接口设计
112112

113113
```rust
114+
// Array
115+
pub trait Array: Sized + Send + Sync + 'static {
116+
type Builder: ArrayBuilder<Array = Self>;
117+
type Item: ToOwned + ?Sized;
118+
fn get(&self, idx: usize) -> Option<&Self::Item>;
119+
fn len(&self) -> usize;
120+
fn iter(&self) -> ArrayIter<'_, Self> {
121+
ArrayIter::new(self)
122+
}
123+
fn is_empty(&self) -> bool {
124+
self.len() == 0
125+
}
126+
}
127+
128+
pub trait ArrayBuilder: Send + Sync + 'static {
129+
type Array: Array<Builder = Self>;
130+
fn with_capacity(capacity: usize) -> Self;
131+
fn push(&mut self, value: Option<&<Self::Array as Array>::Item>);
132+
fn append(&mut self, other: &Self::Array);
133+
fn finish(self) -> Self::Array;
134+
}
135+
136+
pub trait Primitive:
137+
PartialOrd + PartialEq + Debug + Copy + Send + Sync + Sized + Default + 'static
138+
{
139+
}
140+
141+
pub struct PrimitiveArray<T: Primitive> {...}
142+
impl<T: Primitive> Array for PrimitiveArray<T> {...}
143+
144+
pub struct PrimitiveArrayBuilder<T: Primitive> {...}
145+
impl<T: Primitive> ArrayBuilder for PrimitiveArrayBuilder<T> {...}
146+
147+
pub struct Utf8Array { ... }
148+
impl Array for Utf8Array { ... }
149+
150+
pub struct Utf8ArrayBuilder {...}
151+
impl ArrayBuilder for Utf8ArrayBuilder {...}
152+
153+
pub type BoolArray = PrimitiveArray<bool>;
154+
pub type I32Array = PrimitiveArray<i32>;
155+
pub type F64Array = PrimitiveArray<f64>;
156+
157+
pub enum ArrayImpl {
158+
Bool(BoolArray),
159+
Int32(I32Array),
160+
Float64(F64Array),
161+
Utf8(Utf8Array),
162+
}
163+
164+
pub type BoolArrayBuilder = PrimitiveArrayBuilder<bool>;
165+
pub type I32ArrayBuilder = PrimitiveArrayBuilder<i32>;
166+
pub type F64ArrayBuilder = PrimitiveArrayBuilder<f64>;
167+
168+
pub enum ArrayBuilderImpl {
169+
Bool(BoolArrayBuilder),
170+
Int32(I32ArrayBuilder),
171+
F64(F64ArrayBuilder),
172+
Utf8(Utf8ArrayBuilder),
173+
}
174+
175+
// In-memory storage
114176
pub struct InMemoryStorage {...}
115177

116178
impl InMemoryStorage {

0 commit comments

Comments
 (0)