user212926
user212926

Reputation:

How to build generic tree datastructure with ABAP OO

I want to build a tree datastructure in ABAP. My key requirement is the possibility to use generic objects as node for the tree.

I Java it would look something like this:

public class MyTree<? extends TreeNode> {
(...)
}

My current approach would be to define a class TreeNode which is the super class of all possible nodes inside the tree.

Is there a more elegant way to realize generic types with ABAP OO? Or are there maybe datastructures shipped with SAP that I don't know of?

Upvotes: 3

Views: 2055

Answers (1)

Philipp
Philipp

Reputation: 69663

Most operations on a SORTED TABLE have performance characteristics like a binary tree. I am pretty sure that the internal implementation of sorted tables is some flavor of binary trees (either that or skip-lists).

During my internship I recreated some typical data structures like linked lists or binary trees with ABAP objects and compared their performance to the equivalent native TABLE flavors - the native ones usually had the same complexity classes, but they always performed much faster. Unless you have some very special use-case which requires some exotic data structure, you should try to work with TABLE, SORTED TABLE or HASHED TABLE.

Upvotes: 1

Related Questions