Updating record when referenced by multiple data structures

后端 未结 7 1279
独厮守ぢ
独厮守ぢ 2020-12-10 06:50

Suppose I have a record, e.g. Person, and I want to be able to look this person up through multiple data structures. Maybe there\'s an index by name, another in

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 07:23

    If you need it done efficiently, you'll have to downgrade to mutable datastructures and basically the IO monad.

    These updateable references between objects like in OO are available in Haskell aswell. These are IORefs. There are also thread-safe versions of them: MVar and TVar - the choice between them depends on your concurrerency model.

    This data structure with different kinds of references between objects is called Graph and it happens so that I'm currently working on a Haskell Graph Database project. The project is getting close to its first release. An in-memory datastructure is already implemented, persistence-layer too, all that's left is client and server. So just keep an eye on it. I'll reddit about it on release. The source repository is here: https://github.com/nikita-volkov/graph-db/, though I haven't been pushing updates for some time so it's a bit outdated.

提交回复
热议问题