source: libcfa/src/containers/string.hfa @ 52a2248

ADTast-experimental
Last change on this file since 52a2248 was 08ed947, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

Roll up of string changes for performance testing/improvement, and a couple API features supporting them.

String API changes:
Defining a tuning knob to control the heap growth policy (relapaces former 10% hardcode, downgraded to a default)
Implementing findFrom (allowing find-non-first); leaving find as find-first.

String implementation perf improvements:
Calling C-malloc directly instead of via CFA-alloc.
Replacings loops that copy with memmove calls.
Replacings loops that search for a value with memchr calls.

String perf testing realized:
Makefile supporting several prog-*.cfa, chosen by OPERATION value (implies prog.cfa changes to support the adjusted protocol)
Adjusting the starter/accumulater declarations in PEQ and PTA to behave consistently in cfa v cpp.
Adding tests: allocation, find, normalize, pass-by-val, pass-by-x.
Adding helper shell scripts for: generating flame graphs, collecting/crunching allocation stats using Mubeen's malloc wrappers

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[f450f2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// string -- variable-length, mutable run of text, with value semantics
8//
9// Author           : Michael L. Brooks
10// Created On       : Fri Sep 03 11:00:00 2021
11// Last Modified By : Michael L. Brooks
12// Last Modified On : Fri Sep 03 11:00:00 2021
13// Update Count     : 1
14//
15
16#pragma once
17
18#include <fstream.hfa>
19
20
21// in string_res.hfa
22struct string_res;
23struct charclass_res;
24
25struct string {
26    string_res * inner;
27};
28
29// Getters
30size_t size(const string &s);
31
32// RAII, assignment
33void ?{}( string & this ); // empty string
34void ?{}(string &s, const char* initial); // copy from string literal (NULL-terminated)
35void ?{}(string &s, const char* buffer, size_t bsize); // copy specific length from buffer
36
37void ?{}(string &s, const string & s2);
38void ?{}(string &s, string & s2);
39
40void ?=?(string &s, const char* other); // copy assignment from literal
41void ?=?(string &s, const string &other);
42void ?=?(string &s, char other);
[4b3b352]43string & ?=?(string &s, string &other);  // surprising ret seems to help avoid calls to autogen
44//string ?=?( string &, string ) = void;
[f450f2f]45void ^?{}(string &s);
46
47// Alternate construction: request shared edits
48struct string_WithSharedEdits {
49    string * s;
50};
51string_WithSharedEdits ?`shareEdits( string & this );
52void ?{}( string & this, string_WithSharedEdits src );
53
54// IO Operator
55ofstream & ?|?(ofstream &out, const string &s);
56void ?|?(ofstream &out, const string &s);
57
58// Concatenation
59void ?+=?(string &s, char other); // append a character
60void ?+=?(string &s, const string &s2); // append-concatenate to first string
61void ?+=?(string &s, const char* other); // append-concatenate to first string
62string ?+?(const string &s, char other); // add a character to a copy of the string
63string ?+?(const string &s, const string &s2); // copy and concatenate both strings
64string ?+?(const char* s1, const char* s2); // concatenate both strings
65string ?+?(const string &s, const char* other); // copy and concatenate with NULL-terminated string
66
67// Repetition
68string ?*?(const string &s, size_t factor);
69string ?*?(char c, size_t size);
70string ?*?(const char *s, size_t size);
71
72// Character access
73char ?[?](const string &s, size_t index);
74string ?[?](string &s, size_t index);  // mutable length-1 slice of original
75//char codePointAt(const string &s, size_t index);  // to revisit under Unicode
76
77// Comparisons
78bool ?==?(const string &s, const string &other);
79bool ?!=?(const string &s, const string &other);
80bool ?==?(const string &s, const char* other);
81bool ?!=?(const string &s, const char* other);
82
83// Slicing
84string ?()( string & this, size_t start, size_t end );  // TODO const?
85string ?()( string & this, size_t start);
86
87// String search
88bool contains(const string &s, char ch); // single character
89
90int find(const string &s, char search);
91int find(const string &s, const string &search);
92int find(const string &s, const char* search);
93int find(const string &s, const char* search, size_t searchsize);
94
[08ed947]95int findFrom(const string &s, size_t fromPos, char search);
96int findFrom(const string &s, size_t fromPos, const string &search);
97int findFrom(const string &s, size_t fromPos, const char* search);
98int findFrom(const string &s, size_t fromPos, const char* search, size_t searchsize);
99
[f450f2f]100bool includes(const string &s, const string &search);
101bool includes(const string &s, const char* search);
102bool includes(const string &s, const char* search, size_t searchsize);
103
104bool startsWith(const string &s, const string &prefix);
105bool startsWith(const string &s, const char* prefix);
106bool startsWith(const string &s, const char* prefix, size_t prefixsize);
107
108bool endsWith(const string &s, const string &suffix);
109bool endsWith(const string &s, const char* suffix);
110bool endsWith(const string &s, const char* suffix, size_t suffixsize);
111
112// Modifiers
113void padStart(string &s, size_t n);
114void padStart(string &s, size_t n, char padding);
115void padEnd(string &s, size_t n);
116void padEnd(string &s, size_t n, char padding);
117
118
119
120struct charclass {
121    charclass_res * inner;
122};
123
124void ?{}( charclass & ) = void;
125void ?{}( charclass &, charclass) = void;
126charclass ?=?( charclass &, charclass) = void;
127
128void ?{}( charclass &, const string & chars);
129void ?{}( charclass &, const char * chars );
130void ?{}( charclass &, const char * chars, size_t charssize );
131void ^?{}( charclass & );
132
133int include(const string &s, const charclass &mask);
134
135int exclude(const string &s, const charclass &mask);
136
137/*
138What to do with?
139StrRet include(string &s, const charclass &mask);
140StrRet exclude(string &s, const charclass &mask);
141*/
142
143
Note: See TracBrowser for help on using the repository browser.