如何获得一个clojure数组映射来保持assoc之后的插入顺序? [英] How to get a clojure array-map to maintain insertion order after assoc?

查看:209
本文介绍了如何获得一个clojure数组映射来保持assoc之后的插入顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 array-map ,它是 assoc 一些值。在一定大小后,返回的值是 PersistentHashMap ,而不是原始的 PersistentArrayMap 。我在几个网站上阅读过这种行为。有什么办法强制插入订单,即使在 assoc ?



之后,我确实有一个单独的函数一个 ash-map 和一个键的向量,并按顺序返回一个新鲜的 array-map 键,但这意味着对于每个关联,我必须首先提取关键字,将新关键字用于向量,然后创建一个新的数组映射。似乎kludgey,即使写在一个单独的函数。

是否有一个更直接的语言支持的方式来保持插入顺序,即使在大型(> 10,但< ; 50)keys array-map?

在相关的情况下,我使用数组映射列表作为incanter数据集中的数据,然后输出为excel。 save-xls函数保持键/列的顺序。



谢谢

解决方案

div>

您可以使用有序地图: https://github.com/flatland/ordered

I have an array-map which I am associng some values into it. After a certain size the returned value is a PersistentHashMap rather than the original PersistentArrayMap. I've read about this behavior on a few web sites. Is there any way to force the insertion order even after assoc?

I do have a separate function which will take a ash-map and a vector of keys, and return a "fresh" array-map with keys in this order, but it means that for each assoc, I have to extract the keys first, cons/conj the new key to the vector, then create a new array-map. Seems kludgey, even if written in a separate function.

Is there a more direct language-supported way of keeping insertion order even on large-ish (>10, but < 50) keys array-map?

In case it's relevant, I'm using a list of array-maps as data into an incanter dataset and then outputting to excel. The save-xls function keeps the order of the keys/columns.

Thanks

解决方案

You can use an ordered map: https://github.com/flatland/ordered

这篇关于如何获得一个clojure数组映射来保持assoc之后的插入顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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