Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tempsdb
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
tempsdb
Commits
b3198766
Commit
b3198766
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
add startswith and endswith
parent
24c4c58b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tempsdb/varlen.pxd
+3
-0
3 additions, 0 deletions
tempsdb/varlen.pxd
tempsdb/varlen.pyx
+59
-3
59 additions, 3 deletions
tempsdb/varlen.pyx
with
62 additions
and
3 deletions
tempsdb/varlen.pxd
+
3
−
0
View file @
b3198766
...
...
@@ -44,12 +44,15 @@ cdef class VarlenEntry:
list
item_no
VarlenSeries
parent
bytes
data
long
len
cpdef
int
length
(
self
)
cpdef
bytes
to_bytes
(
self
)
cpdef
unsigned
long
long
timestamp
(
self
)
cpdef
bytes
slice
(
self
,
int
start
,
int
stop
)
cpdef
int
get_byte_at
(
self
,
int
index
)
except
-
1
cpdef
bint
endswith
(
self
,
bytes
v
)
cpdef
bint
startswith
(
self
,
bytes
v
)
cpdef
VarlenSeries
create_varlen_series
(
str
path
,
str
name
,
int
size_struct
,
list
length_profile
,
...
...
This diff is collapsed.
Click to expand it.
tempsdb/varlen.pyx
+
59
−
3
View file @
b3198766
...
...
@@ -30,6 +30,60 @@ cdef class VarlenEntry:
self
.
item_no
=
item_no
self
.
chunks
=
chunks
self
.
data
=
None
#: cached data, filled in by to_bytes
self
.
len
=
-
1
cpdef
bint
startswith
(
self
,
bytes
v
):
"""
Check whether this sequence starts with provided bytes.
This will run faster than `bytes(v).startswith(b
'
test
'
)` since it will
fetch only the required amount of bytes.
:param v: bytes to check
:return: whether the sequence starts with provided bytes
"""
if
self
.
data
is
not
None
:
return
self
.
data
.
startswith
(
v
)
if
self
.
len
>
-
1
:
if
len
(
v
)
>
self
.
len
:
return
False
else
:
if
len
(
v
)
>
self
.
length
():
return
False
cdef
bytes
b
=
self
.
slice
(
0
,
self
.
length
)
return
self
.
length
==
v
cpdef
bint
endswith
(
self
,
bytes
v
):
"""
Check whether this sequence ends with provided bytes.
This will run faster than `bytes(v).endswith(b
'
test
'
)` since it will
fetch only the required amount of bytes.
:param v: bytes to check
:return: whether the sequence ends with provided bytes
"""
if
self
.
data
is
not
None
:
return
self
.
data
.
endswith
(
v
)
cdef
int
len_v
=
len
(
v
)
if
self
.
len
>
-
1
:
if
len_v
>
self
.
len
:
return
False
else
:
if
len_v
>
self
.
length
():
return
False
cdef
bytes
b
=
self
.
slice
(
self
.
len
-
len_v
,
self
.
len
)
return
b
==
v
def
__bool__
(
self
)
->
bool
:
if
self
.
data
is
not
None
:
return
bool
(
self
.
data
)
return
bool
(
self
.
length
())
cpdef
unsigned
long
long
timestamp
(
self
):
"""
...
...
@@ -41,11 +95,12 @@ cdef class VarlenEntry:
"""
:return: self length
"""
if
self
.
data
is
not
None
:
return
len
(
self
.
data
)
if
self
.
len
>
-
1
:
return
self
.
len
cdef
bytes
b
=
self
.
chunks
[
0
].
get_slice_of_piece_at
(
self
.
item_no
[
0
],
0
,
self
.
parent
.
size_field
)
b
=
b
[:
self
.
parent
.
size_field
]
return
self
.
parent
.
size_struct
.
unpack
(
b
)[
0
]
self
.
len
=
self
.
parent
.
size_struct
.
unpack
(
b
)[
0
]
return
self
.
len
def
__contains__
(
self
,
item
:
bytes
)
->
bool
:
return
item
in
self
.
to_bytes
()
...
...
@@ -158,6 +213,7 @@ cdef class VarlenEntry:
segment
+=
1
if
self
.
data
is
None
:
self
.
data
=
bytes
(
b
)
self
.
len
=
length
return
self
.
data
def
__iter__
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment