Writing data requiring pointers / references in Clojure?

I was working on a toy in a database in Clojure and wanted to implement B + Tree. When I started thinking about this, I realized that there could be no way to have something like a pointer / link to other nodes in Clojure. It doesn’t matter for something like BST or many other tree structures, since all you need is to store a child Node. But what am I doing in something like a B + tree where I need to be able to reference Node sibling?

When searching for solutions, I came across a message in Google Groups about how you are not implementing a doubly-linked list in Clojure, because there are other ways to do things in Clojure.

What should I do for the B + tree?

+5
source share
2 answers

It is not so difficult to have references to objects in clojure; but, as a rule, these links are immutable. This is immutability, which makes a doubly linked list impossible, because, unlike a singly linked list, you cannot change any part of it without creating a mutation somewhere.

To see this, suppose I have a separate list,

a -> b -> c

and suppose I want to change his chapter. I can do this by changing the whole list. I create a new list, creating a new value for the head value and reuse the tail:

a'-> b -> c

But doubly linked lists are impossible. Therefore, in clojure and other functional languages, we sometimes use zipper in such situations.

, Clojure - ? , , concurrency, Clojure vars, refs, atoms ..

, deftype , . java Clojure .

? , , swizzling , .

, , B-, . , , - . -, , , - couchDB, . , - , . ​​ , . RethinkDB , IIRC.

+3

Chouser finger trees Clojure, , , .

, , B + - .

, " ".

+1

All Articles