471,336 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

Organizing Sequential Data (TimeStamps) Overthinking?

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

Oct 19 '07 #1
6 1506
On Oct 19, 7:26 pm, xkenneth <xkenn...@gmail.comwrote:
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.

--
Paul Hankin

Oct 19 '07 #2
xkenneth wrote:
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
Oct 19 '07 #3
On Oct 19, 11:26 am, xkenneth <xkenn...@gmail.comwrote:
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
Oct 19 '07 #4
On Oct 19, 11:26 am, xkenneth <xkenn...@gmail.comwrote:
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
Oct 19 '07 #5
On Oct 19, 11:26 am, xkenneth <xkenn...@gmail.comwrote:
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
Oct 19 '07 #6
En Fri, 19 Oct 2007 16:17:41 -0300, Raymond Hettinger <py****@rcn.com>
escribió:
Try heapq.nsmallest().
En Fri, 19 Oct 2007 16:20:29 -0300, Raymond Hettinger <py****@rcn.com>
escribió:
Try heapq.nsmallest().
En Fri, 19 Oct 2007 17:22:13 -0300, Raymond Hettinger <py****@rcn.com>
escribió:
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

--
Gabriel Genellina

Oct 19 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by lkrubner | last post: by
reply views Thread by GBartgo | last post: by
3 posts views Thread by Jamie | last post: by
5 posts views Thread by Robert Schuldenfrei | last post: by
4 posts views Thread by Craig G | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.