mutable

Are new vectors created even if the old ones aren't used anymore?

爱⌒轻易说出口 提交于 2019-12-05 05:49:28
This question is about the Data.Vector package. Given the fact that I'll never use the old value of a certain cell once the cell is updated. Will the update operation always create a new vector, reflecting the update, or will it be done as an in-place update ? Note: I know about Data.Vector.Mutable No, but something even better can happen. Data.Vector is built using "stream fusion" . This means that if the sequence of operations that you are performing to build up and then tear down the vector can be fused away, then the Vector itself will never even be constructed and your code will turn into

Are String Arrays mutable?

回眸只為那壹抹淺笑 提交于 2019-12-05 04:33:15
I wonder if String arrays in Java are mutable ? I know that Strings are immutable, but how about string Arrays ? If I have a string array, and change the content, will a new string object be created ? Or will the actual value just be changed ? Thanks in advance Luiggi Mendoza The String s contained in the String[] are indeed immutable, but the array is mutable. This is well explained in this answer : Immutability means that objects of a certain type can not change in any meaningful way to outside observers Integer , String , etc are immutable Generally all value types should be Array objects

Caching expensive data in C++ - function-scoped statics vs mutable member variables

别来无恙 提交于 2019-12-05 03:38:38
I've got a relatively expensive data-fetching operation that I want to cache the results of. This operation is called from const methods, roughly like this: double AdjustData(double d, int key) const { double factor = LongRunningOperationToFetchFactor(key); return factor * d; } I'd like AdjustData to remain const , but I want to cache out the factor so I only fetch it the first time. At present I'm using a mutable map<int, double> to store the result (the map being from key to factor ), but I'm thinking using a function-scoped static might be a better solution - this factor is only needed by

Understanding immutable composite types with fields of mutable types in Julia

爷,独闯天下 提交于 2019-12-05 02:10:22
Initial note: I'm working in Julia, but this question probably applies to many languages. Setup: I have a composite type as follows: type MyType x::Vector{String} end I write some methods to act on MyType . For example, I write a method that allows me to insert a new element in x , e.g. function insert!(d::MyType, itemToInsert::String) . Question: Should MyType be mutable or immutable? My understanding: I've read the Julia docs on this, as well as more general (and highly upvoted) questions on Stackoverflow (e.g. here or here ), but I still don't really have a good handle on what it means to

Haskell Data Type With References

会有一股神秘感。 提交于 2019-12-04 21:45:18
问题 I'm implementing Ukkonen's algorithm, which requires that all leaves of a tree contain a reference to the same integer, and I'm doing it in Haskell to learn more about the language. However, I'm having a hard time writing out a data type that does this. -- Node has children, indexes of info on the edge -- to it, and an optional suffix link. -- Leaf has a beginning index of the info, but the -- end index is always an incrementing variable index. data STree = Node [STree] (Int, Int) (Maybe

Why Mutable map becomes immutable automatically in UserDefinedAggregateFunction(UDAF) in Spark

巧了我就是萌 提交于 2019-12-04 20:58:28
问题 I am trying to define a UserDefinedAggregateFunction(UDAF) in Spark, which counts the number of occurrences for each unique values in a column of a group. This is an example: Suppose I have a dataframe df like this, +----+----+ |col1|col2| +----+----+ | a| a1| | a| a1| | a| a2| | b| b1| | b| b2| | b| b3| | b| b1| | b| b1| +----+----+ I will have a UDAF DistinctValues val func = new DistinctValues Then I apply it to the dataframe df val agg_value = df.groupBy("col1").agg(func(col("col2")).as(

Is an immutable Bitmap faster then a mutable one?

半腔热情 提交于 2019-12-04 17:06:49
问题 The Bitmap class has a method copy() with the signature below: public Bitmap copy(Bitmap.Config config, boolean isMutable) Is there a performance difference between a mutable and an immutable Bitmap ? 回答1: Romain Guy answered in the comments: To answer the original question: no, there is no performance difference. There are some optimizations we could implement for mutable bitmaps though. Hopefully in a future release :) 回答2: There is no performance difference. This will not affect the

Why tuple is not mutable in Python? [duplicate]

怎甘沉沦 提交于 2019-12-04 13:18:28
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why are python strings and tuples are made immutable? What lower-level design makes tuple not mutable in Python? Why this feature is useful? 回答1: A few reasons: Mutable objects like lists cannot be used as dictionary keys or set members in Python, since they are not hashable. If lists were given __hash__ methods based on their contents, the values returned could change as the contents change, which violates the

Is modifying a value type from within a using statement undefined behavior?

落花浮王杯 提交于 2019-12-04 10:49:54
问题 This one's really an offshoot of this question, but I think it deserves its own answer. According to section 15.13 of the ECMA-334 (on the using statement, below referred to as resource-acquisition ): Local variables declared in a resource-acquisition are read-only, and shall include an initializer. A compile-time error occurs if the embedded statement attempts to modify these local variables (via assignment or the ++ and -- operators) or pass them as ref or out parameters. This seems to

Java Mutable BigInteger Class

杀马特。学长 韩版系。学妹 提交于 2019-12-04 08:16:35
问题 I am doing calculations with BigIntegers that uses a loop that calls multiply() about 100 billion times, and the new object creation from the BigInteger is making it very slow. I was hoping somebody had written or found a MutableBigInteger class. I found the MutableBigInteger in the java.math package, but it is private and when I copy the code into a new class, many errors come up, most of which I don't know how to fix. What implementations exist of a Java class like MutableBigInteger that