Clojure从指定位置的向量中删除项 [英] Clojure Remove item from Vector at a Specified Location

查看:142
本文介绍了Clojure从指定位置的向量中删除项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以从基于索引的向量中删除项目,因为我现在使用subvec来拆分向量并重新创建它。我正在寻找向量的assoc的反向?

Is there a way to remove an item from a vector based on index as of now i am using subvec to split the vector and recreate it again. I am looking for the reverse of assoc for vectors?

推荐答案

subvec 可能是最好的方法。 Clojure文档说 subvec O(1)并且非常快,因为结果向量与原始共享结构,不进行修剪

subvec is probably the best way. The Clojure docs say subvec is "O(1) and very fast, as the resulting vector shares structure with the original and no trimming is done". The alternative would be walking the vector and building a new one while skipping certain elements, which would be slower.

从向量的中间删除元素不是某种向量都是擅长的。如果你经常这样做,考虑使用哈希映射,所以你可以使用 dissoc

Removing elements from the middle of a vector isn't something vectors are necessarily good at. If you have to do this often, consider using a hash-map so you can use dissoc.

这篇关于Clojure从指定位置的向量中删除项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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