以简单的方式解释持久性数据结构 [英] Explaining persistent data structures in simple terms

查看:163
本文介绍了以简单的方式解释持久性数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Python Python库,实现一些持久的数据结构(主要作为学习练习)。然而,我开始学习,向不熟悉他们的人解释持久的数据结构可能是困难的。有人可以帮助我想到一个简单的(或至少是最不复杂的)方法来描述持久的数据结构吗?

I'm working on a library for Python that implements some persistent data structures (mainly as a learning exercise). However, I'm beginning to learn that explaining persistent data structures to people unfamiliar with them can be difficult. Can someone help me think of an easy (or at least the least complicated) way to describe persistent data structures to them?

我有几个人告诉我我所拥有的文档有点令人困惑。

I've had a couple of people tell me that the documentation that I have is somewhat confusing.

(在任何人询问之前,不要将持久化的数据结构保留在文件系统中。数据结构,如果你不清楚这一点。)

(And before anyone asks, no I don't mean persistent data structures as in persisted to the file system. Google persistent data structures if you're unclear on this.)

推荐答案

尝试这个:

持续数据结构是与数组或列表不同的数据结构,始终保留其原始结构和内容。

Persistent data structures are data structures which, unlike arrays or lists, always preserve their original structure and contents.

它们实际上是不可变的 - 而不是改变结构,任何计算将产生一个新的复制,使原始结构保持不变。而传统的数据结构遵循一个必须的(基于变化的)哲学,持久的数据结构通常用于函数式编程,在极端情况下,根本不允许任何变化。这个范例的优点是持久的数据更安全,通常更容易处理,甚至防止与意外的更改和多线程问题相关的错误。许多问题可以以更简洁的方式在功能上进行制定。

They are effectively immutable - instead of changing such a structure, any computation will yield a new copy leaving the original structure unchanged. Whereas conventional data structures follow an imperative (change-based) philosophy, persistent ones are commonly used in functional programming where, in extreme cases, no change is allowed at all. The advantage of this paradigm is that persistent data are much safer, often easier to handle and even preventing bugs connected to unintended change and multithreading issues. Many problems can be formulated functionally in a much more concise way.

非持久性数据结构的示例:列表(向量列表)

Example for a non-persistent data structure: The list (vector-list)

list = [1, 2, 3]
# List is [1, 2, 3]

list += [4]
# Added an element at the end

list[0] = 42
# We changed the first element to 42
# List is [42, 2, 3, 4]

持久性示例:链接列表(Haskell)

Persistence example: Linked lists (Haskell)

list = [1, 2, 3]
# List is [1, 2, 3]

list2 = 0 : list
# List2 combines [0] and [1, 2, 3] to [0, 1, 2, 3]
# List is still [1, 2, 3]

list3 = updateAt 0 42 list
# List3 contains the elements of list2 with the first one set to 42
# List and List2 still hold their original values

这篇关于以简单的方式解释持久性数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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