功能/不可变数据结构的JVM? [英] Functional/Immutable Data Structures for the JVM?

查看:163
本文介绍了功能/不可变数据结构的JVM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道Java / JVM数据结构库提供功能(也就是功能上的不变或持久)熟悉的Java数据结构的等价物?



通过功能我的意思是对象本身是不可变的,而对这些对象的修改在适当的情况下返回与父对象共享相同内部的新对象(为了在时间和空间上都有效率;一个天真的实现只能复制整个每个写的东西)。



很像Java的并发库,这似乎不像我可以或应该实现自己的东西,所以有一个功能数据结构库我可以在JVM中使用。

解决方案

Clojure的不可变和持久的数据结构已经被提取为Java库。您可以在 http://github.com/krukow/clj-ds 找到它们。这些数据结构不依赖于Clojure运行时,因此可以在应用程序的类路径中使用 clojure.jar 。他们已被授权使用Java代码工作顺利。



请注意,使用这些不可变数据结构在Java中可能不是惯例。



github页面没有用于下载的jar。您将不得不自己检出来源并建造瓶子。


Does anyone know of a Java/JVM data structure library providing functional (a.k.a. immutable, or "persistent" in the functional sense) equivalents of the familiar Java data structures?

By "functional" I mean that the objects themselves are immutable, while modifications to those objects return new objects sharing the same internals as the parent object where appropriate (for efficiency in both time and space; a naïve implementation could just copy the whole thing on every write).

Much like Java's concurrency libraries, this doesn't seem like something I can or should implement myself, so it would be nice to have a functional data structure library I can use in the JVM.

解决方案

Clojure's immutable and persistent data structures have been extracted as a Java library. You can find them at http://github.com/krukow/clj-ds. These data structures are not dependent on the Clojure runtime and hence can be used without the clojure.jar in your application's classpath. They have been generified to work smoothly with Java code.

Please make a note that working with these immutable data structures may not be idiomatic in Java.

The github page does not have a jar for download. You will have to checkout the source and build the jar yourself.

这篇关于功能/不可变数据结构的JVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆