Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

(Double) Linked Lists

Name: Anonymous 2008-04-27 16:01

I've been trying to write a little forum application that scales to million of threads in a category and million posts in a thread. The idea is that viewing a category or thread on any page will only take n+const key lookups in a database (like berkeleydb) where n is the number of items (threads or posts) on the page.

Implementing threads and posts as double linked lists makes it really easy to view the oldest and newest items (and adding new items) but obviously pagination doesn't work at all and also deletion is going to be a bitch because you have to "find" the item first.

I've been thinking about adding "shortcuts" to every 10th, 100th, 1000th, etc item to the next 10th, 100th, 1000th, etc item, but then deleting becomes very very expensive because you possibly have to update thousands of shortcuts. Is there a solution that doesn't suffer from having one really bad operation (or requires in-memory indices)? Or maybe a n+log(items)+const solution...

This is just a thought experiment about data structures but it has been driving me kinda nuts lately :p

Name: Anonymous 2008-04-27 16:03

>>1
linked lists, so i didn't learn much more about it until after she told me to stop replying to these posts, for the cudders! <a href="http://dis.4chan.org/read/prog/1206639378/">croma</a> gtfo for the cudders! gtfo for the cudders! gtfo for each type of block, the loop checking function, and the loop change offset, like this. block blocks[] = &ret->lines; /* in case of gnu emacs had been numbered "1.x.x", but i think it's sending some garbage data

Name: Anonymous 2008-04-27 16:19

>>2
Stop trying to force markov chains as a meme

>>1
Something like pointer += sizeof(single item) * threadnum?

Name: Anonymous 2008-04-27 16:34

>>3

They items aren't fixed sized obviously or this would be trivial

Name: Anonymous 2008-04-27 16:38

Skip lists. Now gtfo.

Name: Anonymous 2008-04-27 16:41

Berkeley DB doesn't scale well, and has little or no support for concurrency.

Read up on how relational databases store their data.

Name: Anonymous 2008-04-27 16:45

>>5

Thanks, that's a very interesting structure

>>6

Not what I asked

Name: Anonymous 2008-04-27 16:50

>>7
SECONDLY, THIS IS /prog/ DO NOT DEMAND USEFUL ANSWERS THE WAY YOU WANT THEM TO BE.


You have no idea how long I've been waiting for an opportunity to use this line.

Name: Anonymous 2008-04-27 16:53

>>7
Note that I very carefully avoided saying ``use a relational database'' -- just learn more about their structure and implementation. Doing so will help you better design what you are trying to accomplish.

Name: Anonymous 2008-04-27 16:55

>>8

Okay sorry

Oh yeah, and

>>6

What is a good DBMS for key/value lookups then?

Name: Anonymous 2008-04-27 17:02

>>9

Yeah, I read that right, I know about B trees and whatever. The problem is a bit different though, I'm trying to set up a data structure on top of an key/value datastructure (which itself will probably be implemented as a btree).

Name: Anonymous 2008-04-27 17:56

You're using Google's AppEngine here, right?

Name: Anonymous 2008-04-27 18:04

1) #include <list>
2) ????
3) STL PROFIT

Name: Anonymous 2008-04-27 18:08

1) #include <haxmyanus>
2) ????
3) anus profit

Name: Anonymous 2008-04-27 18:52

>>12
Obviously not, Google App Engine neither provides a BerkleyDB backend, nor does the infrastructure support using one (no script-accessible writable files).

Name: Anonymous 2008-04-27 19:41

>>12
In FIOC there's a "list" data type built in, what >>1 is considering is obviously low-level.

BTW, looking at FIOC's lists implementation may be useful.

Name: Anonymous 2008-04-27 19:49

>>4
I can't imagine a linked list implementation that is not fixed-size. Even if you store "variable sized" strings, you are actually storing a pointer the address of that string, which is often the same size of an int.

Name: Anonymous 2008-04-28 8:32

>>17

Well, you store the next/previous item inside the value, so you grab an item by it's key (let's say post53) and in the value there's the post ids to the next and previous post.

Name: Anonymous 2008-04-28 10:43

Why do you need to remove posts/threads?

Name: Anonymous 2008-04-28 12:14

>>19

Catnarok

Name: Anonymous 2008-04-28 12:36

>>19

Because?

Name: Anonymous 2008-04-28 12:48

This idea is stupid because:

1. ``Millions of threads''.

Name: Anonymous 2008-04-28 13:44

Listen to >>19, don't bother deleting threads and just have a field to mark them as deleted.

Name: Anonymous 2008-04-29 20:00

>>23
Or reuse the positions, changing the thread id.

Name: Anonymous 2008-04-29 20:15

>>24
Or fuck the positions and change the next/prev pointers of the next/prev threads.

Name: Anonymous 2008-04-29 20:34

You aren't going to find a suitable hierarchical DBMS for this. The relational functionality of an RDBMS isn't really meant for this. So the DB implementation is moot.

You need to focus on the structure of your data. And your best option is a modified preorder tree traversal.

Each node in your hierarchy stores a left and a right value. Together these numbers specify where in the tree the node is. You can use simple arithmetic to figure out all kinds of info on the node.

If a nodes right number = 1 + left then it has no children.
Everything with a left and right number between a given nodes left and right number is a descendant of the node.
The number of decedent is (right – left - 1) / 2
The path to the node is all nodes with a left number less than the nodes left number and a right number greater than the nodes right number.
And so on...

Updates to nodes are tricker, and if you are following you will realize there is some seeming inefficiencies in it. But there are ways of lessening that. And given the incredible efficiencies of look-ups, it should be appropriate for this implementation.

Name: Anonymous 2008-04-29 22:15

I was thinking once along the lines as >>1.  I wondered if a linked list of fixed length arrays would avoid having any really bad operations.  The hope would be that array length could be large enough to make the whole thing efficient but small enough that 'bad' operations on the array are still doable (like insertion to the middle).

Name: Anonymous 2008-04-30 3:29

>>27

did not understand

>>26

Name: Anonymous 2008-04-30 4:36

jesus fuck you fucking nigger twats any self-respecting RDBMS can handle this stupid shit fine without you having to wrangle you fucking brains to figure out how to bastardize the incorrect data structure for the job.

``SELECT p.* FROM posts p WHERE p.thread_id=4085 ORDER BY p.post_id LIMIT 99 OFFSET 5837''

Obviously you're not going to be able to display all million posts of a thread at once, but that's going to break other shit (ie, your fucking pipes) before the DB collapses.

If you're seriously in a situation where you're generating enough content to NEED such a system, you're ass is gonna be fucking toast -- you're not going to be able to handle the entire fucker on a single machine. Fuck, just look at the goddamn storage requirements of such a system:

1000000 threads * 1000000 posts/thread * 200B/post
= 2*1014B
= 181TB

Get your goddamn head out of the clouds and just fucking implement something, then see how well it performs, THEN try to figure out goals. Don't just bullshit numbers and then decide to use a stupid ass bullshit datastructure you learned about in Computer Science III. Read SICP.

I don't give a shit if IHBT and IHBTE -- I'm drunk as shit right now and you niggers are the closest thing I have to a goddamn friend in this stupid fucking world. fuckking sage.

Name: Anonymous 2008-04-30 5:53

you niggers are the closest thing I have to a goddamn friend in this stupid fucking world
;_;

Name: Anonymous 2008-04-30 6:41

ITT BAWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

Name: Anonymous 2008-04-30 7:50

I'm not a nigger.

Name: Anonymous 2008-04-30 12:45

>>29
I like you. You are a good person.

Name: vixey 2008-04-30 12:51

ima retard

Name: Anonymous 2008-04-30 13:55

>>29
>I'm drunk as shit right now and you niggers are the closest thing I have to a goddamn friend in this stupid fucking world. fuckking sage.

Same here, fuck yeah.

Name: Anonymous 2008-04-30 16:46

>>29
king

Name: Anonymous 2008-04-30 17:04

>>29
/prog/: WHERE EVERY BAAADY KNOWS YOUR NAAAME

Name: Anonymous 2008-04-30 18:18

>>37
Back to bed Christopher

Name: Anonymous 2008-04-30 19:50

>>1
BTW, hash tables?

Name: Anonymous 2008-04-30 23:12

>>39
RDBMSs are basically hash tables anyway (ISAM trees).
Or B-trees, which are actually worse, since binary trees have O(n) worst case performance. So you'd be better off sticking with MyISAM

Name: Anonymous 2008-04-30 23:29

>>40
Hash tables have O(n) worst case performance too, but you can't rearrange them to fix it.

Name: Anonymous 2008-04-30 23:58

>>41
O(n) until they're saturated.

>>40
binary trees have O(n) worst case performance
Did you mean O(log n)?

Name: Anonymous 2008-05-01 1:25

>>42
Did you mean O(log n)?
Worst case: A degenerate tree, which is essentially a linked list, which is O(n)

Name: Anonymous 2008-05-01 2:10

>>43
Such a thing wouldn't happen if you rebalance the tree when modifying it.

Name: Anonymous 2008-05-01 23:00

>>45

You can't rebalance a B-tree. But you could rebalance a hash table.

Name: Anonymous 2008-05-01 23:32

>>45
You can rebalance a B-tree, but you cannot tune a fish.

Name: Anonymous 2008-05-01 23:55

>>45
Your post has severe internal inconsistencies. Please fsck before mounting.

Name: Anonymous 2008-05-02 0:42

FSCK MY ANUS

Name: HAX MY ANUS MEME FAN 2008-05-02 0:55

>>48
I do not endorse this.

Name: Anonymous 2008-05-02 1:16

>>48
But you can't tune a fish sandwich.

Name: Anonymous 2008-05-02 1:31

>>50
But you can sandwich a fish tune.

Name: Anonymous 2008-05-02 2:39

ITT, kids who don't understand the practicalities of implementing this. And who don't understand what a modified preorder tree traversal is, or why its the best solution.

Name: Anonymous 2008-05-03 0:50

>>52
fag

Name: Anonymous 2010-11-27 17:08

Name: Anonymous 2010-12-21 7:22

Name: Sgt.Kabukiman䖉 2012-05-22 23:32

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List