将 vector 整理
This commit is contained in:
1 parent
bc6c32b1da
commit
9914e150ef
1 file changed
+3
-5
@@ -1,5 +1,3 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
import memhub
|
||||
|
||||
|
||||
@@ -23,7 +21,7 @@ class Vector[T]():
|
||||
self._grow()
|
||||
if self.length >= self.capacity: return
|
||||
offset: uint64 = uint64(self.data) + self.length * self.elem_size
|
||||
dst: T* = (T*)offset # typed pointer: store whole T, not its first byte
|
||||
dst: T* = T*(offset) # typed pointer: store whole T, not its first byte
|
||||
*dst = value
|
||||
self.length += 1
|
||||
|
||||
@@ -40,14 +38,14 @@ class Vector[T]():
|
||||
def get(self, index: sizet) -> T:
|
||||
if self.data == None: return T(0)
|
||||
offset: uint64 = uint64(self.data) + index * self.elem_size
|
||||
typed_ptr = (T*)offset
|
||||
typed_ptr = T*(offset)
|
||||
return *typed_ptr
|
||||
|
||||
def set(self, index: sizet, value: T):
|
||||
if index >= self.length: return
|
||||
if self.data == None: return
|
||||
offset: uint64 = uint64(self.data) + index * self.elem_size
|
||||
dst: T* = (T*)offset # typed pointer: store whole T, not its first byte
|
||||
dst: T* = T*(offset) # typed pointer: store whole T, not its first byte
|
||||
*dst = value
|
||||
|
||||
def len(self) -> sizet:
|
||||
|
||||
Reference in new issue
Block a user