Organizing Sequential Data (TimeStamps) Overthinking?

X

xkenneth

All,

Just a quick question. I want to be able to have a data structure
that organizes data (timestamps I'm working with) sequentially, so
that i can easily retrieve the first x amount of timeStamps without
iterating over a list. My thought was to use a binary tree, am i
overthinking the problem to try and implement this structure inside of
python? I was also hoping this would already be done for me.

Regards,
Ken
 
P

Paul Hankin

Just a quick question. I want to be able to have a data structure
that organizes data (timestamps I'm working with) sequentially, so
that i can easily retrieve the first x amount of timeStamps without
iterating over a list. My thought was to use a binary tree, am i
overthinking the problem to try and implement this structure inside of
python? I was also hoping this would already be done for me.

If you're only iterating once, store your data in a list, and sort it
when you need to iterate. If you only want the n largest (or smallest)
timestamps - as suggested by your question - keep your data in a list,
and use heapq.nlargest (or heapq.nsmallest).

In fact, I'd try these even if you think you really need a binary
tree: it might be fast enough anyway.
 
L

Larry Bates

xkenneth said:
All,

Just a quick question. I want to be able to have a data structure
that organizes data (timestamps I'm working with) sequentially, so
that i can easily retrieve the first x amount of timeStamps without
iterating over a list. My thought was to use a binary tree, am i
overthinking the problem to try and implement this structure inside of
python? I was also hoping this would already be done for me.

Regards,
Ken
Sounds a little like premature optimization here. It depends on how many
timestamps you are talking about. Certainly if you have a lot (millions),
you should implement binary search, but I would write code first and if it is
too slow, fix that part.

-Larry
 
R

Raymond Hettinger

All,

Just a quick question. I want to be able to have a data structure
that organizes data (timestamps I'm working with) sequentially, so
that i can easily retrieve the first x amount of timeStamps without
iterating over a list. My thought was to use a binary tree, am i
overthinking the problem to try and implement this structure inside of
python? I was also hoping this would already be done for me.

Try heapq.nsmallest().


Raymond
 
R

Raymond Hettinger

All,

Just a quick question. I want to be able to have a data structure
that organizes data (timestamps I'm working with) sequentially, so
that i can easily retrieve the first x amount of timeStamps without
iterating over a list. My thought was to use a binary tree, am i
overthinking the problem to try and implement this structure inside of
python? I was also hoping this would already be done for me.

Try heapq.nsmallest().


Raymond
 
R

Raymond Hettinger

All,

Just a quick question. I want to be able to have a data structure
that organizes data (timestamps I'm working with) sequentially, so
that i can easily retrieve the first x amount of timeStamps without
iterating over a list. My thought was to use a binary tree, am i
overthinking the problem to try and implement this structure inside of
python? I was also hoping this would already be done for me.

Try heapq.nsmallest().


Raymond
 
G

Gabriel Genellina

Try heapq.nsmallest().

Try heapq.nsmallest().

Try heapq.nsmallest().


“Just the place for a Snark!†the Bellman cried,
As he landed his crew with care;
Supporting each man on the top of the tide
By a finger entwined in his hair.
“Just the place for a Snark! I have said it twice:
That alone should encourage the crew.
Just the place for a Snark! I have said it thrice:
What I tell you three times is true.â€

THE HUNTING OF THE SNARK
an Agony in Eight Fits
by Lewis Carroll
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top