Skip to content

Commit

Permalink
Major algorithm change to pass test #28
Browse files Browse the repository at this point in the history
2008-10-06  Armin Burgmeier  <[email protected]>

	* libinfinity/adopted/inf-adopted-operation.h:
	* libinfinity/adopted/inf-adopted-operation.c: Added two new virtual
	functions, need_concurrency_id() and get_concurrency_id(). These are
	used to correctly handle situations when two requests insert text at
	the same position concurrently.

	* libinfinity/adopted/inf-adopted-request.h:
	* libinfinity/adopted/inf-adopted-request.c: Added
	inf_adopted_request_need_concurrency_id() and
	inf_adopted_request_get_concurrency_id() which are simple wrapper
	functions for the underlying operation functions.

	* libinfinity/adopted/inf-adopted-algorithm.c: If a concurrency ID is
	needed during transformation, then acquire one from the same requests
	in a previous state.

	* libinfinity/adopted/inf-adopted-no-operation.c:
	* libinfinity/adopted/inf-adopted-split-operation.c: Implement the two
	new virtual functions.

	* libinftext/inf-text-pword.h:
	* libinftext/inf-text-pword.c: Removed, since pwords are no longer
	used. These did not handle the situation described above well enough,
	since the algorithm did not pass one of the tests in test/session
	since the request cache has been introduced (see my change from
	2008-02-22). The test in question is now test #28.

	Also, the adOPTed algorithm relies on the fact that it must not matter
	on which path a request has been transformed to reach a certain state.
	The pword concept did not fulfill this requirement.

	* libinftext/Makefile.am: Removed the files from the build.

	* libinftext/inf-text-insert-operation.h:
	* libinftext/inf-text-insert-operation.c: Added
	inf_text_insert_operation_need_concurrency_id() and
	inf_text_insert_operation_get_concurrency_id(), and replaced the
	get_pword() virtual function by get_position().

	* libinftext/inf-text-delete-operation.h:
	* libinftext/inf-text-delete-operation.c: Added
	inf_text_delete_operation_need_concurrency_id() and
	inf_text_delete_operation_get_concurrency_id().

	* libinftext/inf-text-default-insert-operation.c:
	* libinftext/inf-text-default-delete-operation.c:
	* libinftext/inf-text-remote-delete-operation.c:
	* libinftext/inf-text-move-operation.c: Implement the two new
	virtual functions from InfAdoptedOperation, and adapt to the
	get_pword() -> get_position() change in InfTextDefaultInsertOperation.

	* test/inf-test-text-operations.c: Correctly supply concurrency IDs
	for the C2 tests to pass.

	* test/inf-test-text-session.c: Always show the random seed used, also
	if given.

	* test/session/*.xml: Regenerated tests.

	* test/session/Makefile.am: Added the new files to the distribution.
  • Loading branch information
aburgm committed Oct 6, 2008
1 parent 755ff78 commit 65eac5a
Show file tree
Hide file tree
Showing 76 changed files with 1,858 additions and 1,387 deletions.
63 changes: 63 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
2008-10-06 Armin Burgmeier <[email protected]>

* libinfinity/adopted/inf-adopted-operation.h:
* libinfinity/adopted/inf-adopted-operation.c: Added two new virtual
functions, need_concurrency_id() and get_concurrency_id(). These are
used to correctly handle situations when two requests insert text at
the same position concurrently.

* libinfinity/adopted/inf-adopted-request.h:
* libinfinity/adopted/inf-adopted-request.c: Added
inf_adopted_request_need_concurrency_id() and
inf_adopted_request_get_concurrency_id() which are simple wrapper
functions for the underlying operation functions.

* libinfinity/adopted/inf-adopted-algorithm.c: If a concurrency ID is
needed during transformation, then acquire one from the same requests
in a previous state.

* libinfinity/adopted/inf-adopted-no-operation.c:
* libinfinity/adopted/inf-adopted-split-operation.c: Implement the two
new virtual functions.

* libinftext/inf-text-pword.h:
* libinftext/inf-text-pword.c: Removed, since pwords are no longer
used. These did not handle the situation described above well enough,
since the algorithm did not pass one of the tests in test/session
since the request cache has been introduced (see my change from
2008-02-22). The test in question is now test #28.

Also, the adOPTed algorithm relies on the fact that it must not matter
on which path a request has been transformed to reach a certain state.
The pword concept did not fulfill this requirement.

* libinftext/Makefile.am: Removed the files from the build.

* libinftext/inf-text-insert-operation.h:
* libinftext/inf-text-insert-operation.c: Added
inf_text_insert_operation_need_concurrency_id() and
inf_text_insert_operation_get_concurrency_id(), and replaced the
get_pword() virtual function by get_position().

* libinftext/inf-text-delete-operation.h:
* libinftext/inf-text-delete-operation.c: Added
inf_text_delete_operation_need_concurrency_id() and
inf_text_delete_operation_get_concurrency_id().

* libinftext/inf-text-default-insert-operation.c:
* libinftext/inf-text-default-delete-operation.c:
* libinftext/inf-text-remote-delete-operation.c:
* libinftext/inf-text-move-operation.c: Implement the two new
virtual functions from InfAdoptedOperation, and adapt to the
get_pword() -> get_position() change in InfTextDefaultInsertOperation.

* test/inf-test-text-operations.c: Correctly supply concurrency IDs
for the C2 tests to pass.

* test/inf-test-text-session.c: Always show the random seed used, also
if given.

* test/session/*.xml: Regenerated tests.

* test/session/Makefile.am: Added the new files to the distribution.

2008-10-06 Armin Burgmeier <[email protected]>

* libinfinity/inf-i18n.h:
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/libinfinity/libinfinity-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ inf_central_method_send_to_net
InfAdoptedOperation
InfAdoptedOperationIface
InfAdoptedOperationFlags
InfAdoptedConcurrencyId
inf_adopted_operation_need_concurrency_id
inf_adopted_operation_get_concurrency_id
inf_adopted_operation_transform
inf_adopted_operation_copy
inf_adopted_operation_get_flags
Expand All @@ -635,6 +638,7 @@ inf_adopted_operation_flags_get_type
INF_ADOPTED_OPERATION_GET_IFACE
inf_adopted_operation_get_type
INF_ADOPTED_TYPE_OPERATION_FLAGS
inf_adopted_concurrency_id_get_type
</SECTION>

<SECTION>
Expand Down Expand Up @@ -670,6 +674,8 @@ inf_adopted_request_get_request_type
inf_adopted_request_get_vector
inf_adopted_request_get_user_id
inf_adopted_request_get_operation
inf_adopted_request_need_concurrency_id
inf_adopted_request_get_concurrency_id
inf_adopted_request_transform
inf_adopted_request_mirror
inf_adopted_request_fold
Expand Down
1 change: 1 addition & 0 deletions docs/reference/libinfinity/libinfinity.types
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ inf_connection_manager_group_get_type
inf_connection_manager_get_type
inf_adopted_session_get_type
inf_adopted_session_record_get_type
inf_adopted_concurrency_id_get_type
inf_adopted_operation_flags_get_type
inf_adopted_operation_get_type
inf_adopted_state_vector_get_type
Expand Down
17 changes: 0 additions & 17 deletions docs/reference/libinftext/libinftext-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ INF_TEXT_DEFAULT_DELETE_OPERATION_GET_CLASS
<FILE>inf-text-insert-operation</FILE>
InfTextInsertOperationIface
inf_text_insert_operation_get_position
inf_text_insert_operation_get_pword
inf_text_insert_operation_get_length
inf_text_insert_operation_transform_insert
inf_text_insert_operation_transform_delete
Expand Down Expand Up @@ -182,22 +181,6 @@ INF_TEXT_IS_MOVE_OPERATION_CLASS
INF_TEXT_MOVE_OPERATION_GET_CLASS
</SECTION>

<SECTION>
<FILE>inf-text-pword</FILE>
InfTextPword
inf_text_pword_new
inf_text_pword_new_proceed
inf_text_pword_copy
inf_text_pword_free
inf_text_pword_get_size
inf_text_pword_get_current
inf_text_pword_get_origin
inf_text_pword_compare
<SUBSECTION Standard>
INF_TEXT_TYPE_PWORD
inf_text_pword_get_type
</SECTION>

<SECTION>
<FILE>inf-text-operations</FILE>
InfTextDeleteOperation
Expand Down
1 change: 0 additions & 1 deletion docs/reference/libinftext/libinftext.types
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
inf_text_pword_get_type
inf_text_default_delete_operation_get_type
inf_text_insert_operation_get_type
inf_text_remote_delete_operation_get_type
Expand Down
111 changes: 69 additions & 42 deletions libinfinity/adopted/inf-adopted-algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ inf_adopted_algorithm_least_common_successor(InfAdoptedAlgorithm* algorithm,
);
}

g_assert(inf_adopted_state_vector_causally_before(first, result));
g_assert(inf_adopted_state_vector_causally_before(second, result));
return result;
}

Expand Down Expand Up @@ -287,6 +289,10 @@ inf_adopted_algorithm_can_undo_redo(InfAdoptedAlgorithm* algorithm,
log = inf_adopted_user_get_request_log(user);
request = inf_adopted_request_log_original_request(log, request);

/* TODO: If other requests need to be undone or redone before request
* can be undone or redone, then we need to include these in the
* vdiff. */

diff = inf_adopted_algorithm_state_vector_vdiff(
algorithm,
inf_adopted_request_get_vector(request),
Expand Down Expand Up @@ -794,6 +800,8 @@ inf_adopted_algorithm_is_reachable(InfAdoptedAlgorithm* algorithm,
}

/* Required by inf_adopted_algorithm_transform_request() */
/* TODO: Remove can_cache parameter, but just check whether request both
* affects the buffer and is reversible? */
static InfAdoptedRequest*
inf_adopted_algorithm_translate_request(InfAdoptedAlgorithm* algorithm,
InfAdoptedRequest* request,
Expand All @@ -812,70 +820,89 @@ inf_adopted_algorithm_transform_request(InfAdoptedAlgorithm* algorithm,
InfAdoptedStateVector* at,
gboolean can_cache)
{
InfAdoptedRequest* request_at;
InfAdoptedRequest* against_at;
InfAdoptedConcurrencyId concurrency_id;
InfAdoptedStateVector* lcs;
InfAdoptedStateVector* request_vec;
InfAdoptedStateVector* against_vec;
InfAdoptedRequest* lcs_against;
InfAdoptedRequest* lcs_request;
InfAdoptedRequest* against_copy;
InfAdoptedRequest* request_copy;
InfAdoptedRequest* result;

request_vec = inf_adopted_request_get_vector(request);
against_vec = inf_adopted_request_get_vector(against);

g_assert(inf_adopted_state_vector_causally_before(request_vec, at));
g_assert(inf_adopted_state_vector_causally_before(against_vec, at));

/* Find least common successor and transform both requests
* through that point. */
lcs = inf_adopted_algorithm_least_common_successor(
algorithm,
request_vec,
against_vec
g_assert(
inf_adopted_state_vector_causally_before(
inf_adopted_request_get_vector(request),
at
)
);
g_assert(
inf_adopted_state_vector_causally_before(
inf_adopted_request_get_vector(against),
at
)
);

g_assert(inf_adopted_state_vector_causally_before(request_vec, lcs));
g_assert(inf_adopted_state_vector_causally_before(against_vec, lcs));
g_assert(inf_adopted_state_vector_causally_before(lcs, at));
/* TODO: We wouldn't need this copy any longer when requests were
* immutable. But we need to profile that. */
request_copy = inf_adopted_request_copy(request);

#if 1
lcs_against = inf_adopted_algorithm_translate_request(
against_at = inf_adopted_algorithm_translate_request(
algorithm,
against,
lcs,
at,
TRUE
);

lcs_request = inf_adopted_algorithm_translate_request(
request_at = inf_adopted_algorithm_translate_request(
algorithm,
request,
lcs,
at,
can_cache
);
#else
lcs_against = against;
lcs_request = request;
#endif
inf_adopted_state_vector_free(lcs);

against_copy = inf_adopted_algorithm_translate_request(
algorithm,
lcs_against,
at,
TRUE
);
concurrency_id = INF_ADOPTED_CONCURRENCY_NONE;
if(inf_adopted_request_need_concurrency_id(request_at, against_at) == TRUE)
{
lcs = inf_adopted_algorithm_least_common_successor(
algorithm,
inf_adopted_request_get_vector(request_copy),
inf_adopted_request_get_vector(against)
);

result = inf_adopted_algorithm_translate_request(
algorithm,
lcs_request,
at,
can_cache
);
g_assert(inf_adopted_state_vector_causally_before(lcs, at));

if(inf_adopted_state_vector_compare(lcs, at) != 0)
{
lcs_against = inf_adopted_algorithm_translate_request(
algorithm,
against,
lcs,
TRUE
);

lcs_request = inf_adopted_algorithm_translate_request(
algorithm,
request_copy,
lcs,
can_cache
);

concurrency_id =
inf_adopted_request_get_concurrency_id(lcs_request, lcs_against);
/*printf("cid: %d\n", concurrency_id);*/
}

inf_adopted_state_vector_free(lcs);
}

g_object_unref(request_copy);

if(can_cache)
result = inf_adopted_request_copy(result);
result = inf_adopted_request_copy(request_at);
else
result = request_at;

inf_adopted_request_transform(result, against_copy);
inf_adopted_request_transform(result, against_at, concurrency_id);
return result;
}

Expand Down
18 changes: 18 additions & 0 deletions libinfinity/adopted/inf-adopted-no-operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <libinfinity/adopted/inf-adopted-no-operation.h>
#include <libinfinity/adopted/inf-adopted-operation.h>
#include <libinfinity/adopted/inf-adopted-concurrency-warning.h>

/**
* SECTION:inf-adopted-no-operation
Expand Down Expand Up @@ -45,6 +46,21 @@ inf_adopted_no_operation_class_init(gpointer g_class,
parent_class = G_OBJECT_CLASS(g_type_class_peek_parent(g_class));
}

static gboolean
inf_adopted_no_operation_need_concurrency_id(InfAdoptedOperation* operation,
InfAdoptedOperation* against)
{
return FALSE;
}

static InfAdoptedConcurrencyId
inf_adopted_no_operation_get_concurrency_id(InfAdoptedOperation* operation,
InfAdoptedOperation* against)
{
_inf_adopted_concurrency_warning(INF_ADOPTED_TYPE_NO_OPERATION);
return INF_ADOPTED_CONCURRENCY_NONE;
}

static InfAdoptedOperation*
inf_adopted_no_operation_transform(InfAdoptedOperation* operation,
InfAdoptedOperation* against,
Expand Down Expand Up @@ -86,6 +102,8 @@ inf_adopted_no_operation_operation_init(gpointer g_iface,
InfAdoptedOperationIface* iface;
iface = (InfAdoptedOperationIface*)g_iface;

iface->need_concurrency_id = inf_adopted_no_operation_need_concurrency_id;
iface->get_concurrency_id = inf_adopted_no_operation_get_concurrency_id;
iface->transform = inf_adopted_no_operation_transform;
iface->copy = inf_adopted_no_operation_copy;
iface->get_flags = inf_adopted_no_operation_get_flags;
Expand Down
Loading

0 comments on commit 65eac5a

Please sign in to comment.