Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any convenient way to create alias of indexes and data in Array2 #56

Closed
qindazhu opened this issue Jun 9, 2020 · 2 comments

Comments

@qindazhu
Copy link
Collaborator

qindazhu commented Jun 9, 2020

As we will declare many classes (Fsa, AuxLabels, Cfsa, etc.) with Array2, wondering if there is any convenient way to create alias of indexes and data so that we can use those alias in functions to make code clear (otherwise we may create those alias in functions again and again)

For example (pseudo code)

using Fsa = Array2<Arc*, int32_t>
alias Fsa::arc_indexes = Fsa::indexes;
alias Fsa::arcs = Fsa::data;

One possible approach I thought of is wrapping Array2 in a struct:

struct Fsa {
 Array2<Arc *, int32_t> m;
 Arc *&arcs = m.data;
 int32_t *&arc_indexes = m.indexes;
};

(Two extra advantages of using struct here are that:

  1. Users cannot misuse class as another class that has the same template parameters in Array2, for example they can not pass Fsa to a function that accepts Cfsa where Fsa = Cfsa = Array2<Arc*, int32_t>)
  2. We can define extra methods in those structs, such as NumStates(), FinalStates(), NumArcs. Otherwise it seems we could just define those methods in Python code (and cannot do this in C++ code)?
    )
@danpovey
Copy link
Collaborator

danpovey commented Jun 9, 2020 via email

@qindazhu
Copy link
Collaborator Author

qindazhu commented Jun 9, 2020

Sure, and will add IndexT size2 in Array2 as the total number of elements in data (from indexes[0] to indexes[size])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants