Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8583031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:26:22+00:00 2026-06-11T21:26:22+00:00

I have been looking for an array type with the following characteristics in Erlang.

  • 0

I have been looking for an array type with the following characteristics in Erlang.

append(vector(), term())        O(1) 
nth(Idx, vector())              O(1)
set(Idx, vector(), term())      O(1)
insert(Idx, vector(), term())   O(N)
remove(Idx, vector())           O(N)

I normally use a tuple for this purpose, but the performance characteristics are not what I would want for large N. My testing shows the following performance characteristics…

erlang:append_element/2          O(N).
erlang:setelement/3              O(N).

I have started on a module based on the clojure.lang.PersistentVector implementation, but if it’s already been done I won’t reinvent the wheel.

Edit:

For those interested, I’ve finished implementing vector.erl … using the same algorithm as clojure.lang.PersistentVector. It has similar performance characteristics as the array module, but has slightly better constant factors on append.

The the following test appends 10000 items per interval and then does 10000 lookups and 10000 updates at random index. All operations are near O(1). The timings in the inner tuple are in microseconds.

3> seq_perf:test(vector, 100000, 10).
{2685854,
 {ok,[{100000,{66966,88437,124376}},
      {200000,{66928,76882,125677}},
      {300000,{68030,76506,116753}},
      {400000,{72429,76852,118263}},
      {500000,{66296,84967,119828}},
      {600000,{66953,78155,116984}},
      {700000,{65996,77815,138046}},
      {800000,{67801,78455,118191}},
      {900000,{69489,77882,114886}},
      {1000000,{67444,80079,118428}}]}}
4> seq_perf:test(array, 100000, 10). 
{2948361,
 {ok,[{100000,{105482,72841,108828}},
      {200000,{123655,78898,124092}},
      {300000,{110023,76130,106806}},
      {400000,{104126,73830,119640}},
      {500000,{104771,72593,110157}},
      {600000,{107306,72543,109713}},
      {700000,{122066,73340,110662}},
      {800000,{105853,72841,110618}},
      {900000,{105267,73090,106529}},
      {1000000,{103445,73206,109939}}]}}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:26:23+00:00Added an answer on June 11, 2026 at 9:26 pm

    Those properties are not possible in a purely functional implementation. The array module (http://www.erlang.org/doc/man/array.html) is a quite good compromise, but if you require O(1) lookup and update, you’ll have to use an ETS table instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking into Adjacency List and Nested Set Model to find the
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking around for a visualization framework that would aid graph visualization
I have been looking online to find documentation for the function in QTP and
I have been looking into AWS spot instances for some jobs however instead of
I have been looking into backbone.js and I can't seem to figure out how
I have been looking at the Thinktecture.IdentityModel.40 library as a way of handling the
I have been looking for an answer to this on Stack Overflow, but I
I have been looking through the source code for the Flash-based Google TV example
I have been looking at this for to long so I am tossing it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.