in-place

What are the best options for Rich Text Editing in Rails?

I'd like to use Rich Text Editing in place on forms in order to let admins change instructions. What are the best options for doing this? [To be more clear - the admins are non-technical but may want to control some formatting without using markup or with as little markup as possible. What I'd like is for them to be able to edit inli...

In-Place Radix Sort

This is a long text. Please bear with me. Boiled down, the question is: does someone know a workable in-place radix sort algorithm? Preliminary I've got a huge number of small fixed-length strings that only use the letters “A”, “C”, “G” and “T” (yes, you've guessed it: DNA) that I want to sort. At the moment, I use std::sort which u...

Updating a java map entry

Hi, I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map, and I want to update the value in a Key-Value pair. Right now, I'm doing it lik this: private Map<String,int> table = new HashMap<String,int>(); public void update(String key, int val) { if( !table.containsKey(key) ) return; Entry...

why is in place merge sort not stable?

The implementation below is stable as it used <= instead of < at line marked XXX. This also makes it more efficient. Is there any reason to use < and not <= at this line? /** class for In place MergeSort **/ class MergeSortAlgorithm extends SortAlgorithm { void sort(int a[], int lo0, int hi0) throws Exception { int lo = lo0; ...

Python: sort a part of a list, in place

Let's say we have a list: a = [4, 8, 1, 7, 3, 0, 5, 2, 6, 9] Now, a.sort() will sort the list in place. What if we want to sort only a part of the list, still in place? In C++ we could write: int array = { 4, 8, 1, 7, 3, 0, 5, 2, 6, 9 }; int * ptr = array; std::sort( ptr + 1, ptr + 4 ); Is there a similar way in Python? ...

How to master in-place array modification algorithms?

I am preparing for a software job interview, and I have trouble with in-place array modifications. For example, in the out-shuffle problem you interleave two halves of an array, so that 1 2 3 4 5 6 7 8 would become 1 5 2 6 3 7 4 8. This question asks for a constant-memory solution (and linear-time, although I'm not sure that's even possi...

Stable separation for two classes of elements in an array

Consider the following problem. We are given an array of elements belonging to one two classes: either red or blue. We have to rearrange the elements of the array so that all blue elements come first (and all red elements follow). The rearrangement must be done is stable fashion, meaning that the relative order of blue elements must be ...

In Ruby, if a hash is not going to be needed later, is it better to use hash.merge!({...}) instead of hash.merge({...}) ?

This happens in Ruby on Rails's View, where there is a hash for another partial. This hash has about 20 key/value pairs. There is (in HAML) - if (some_conditon) = render :partial => 'some_name', :locals => a_hash.merge({ :extra => true }) - else -# a lot more processing, including concatenating the partials and return as json - ...

Keeping only distinct values in tables using Hibernate

I am storing a relatively complex immutable object in a database. There are many many-to-one associations - the object has properties that have properties and so on. I would like to have each object stored only once, based on a business key that is in this case every single property of the object. The workflow is like this: user cre...

What is an in-place constructor in C++?

Possible Duplicate: C++'s placement new What is an in-place constructor in C++? e.g. Datatype *x = new(y) Datatype(); ...

Rotate 2D rectangular array in-place

I have an non-square array like this: const int dim1 = 3, dim2 = 4; int array[12] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12}; and I need to convert it to: {3,6,9,12, 2,5,8,11, 1,4,7,10} that is, rotate/shuffle it counter-clockwise (or clockwise, the algorithm should be similiar)...