source: libcfa/src/containers/string_res.hfa @ 5f53cc3

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 5f53cc3 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: 5.5 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_res -- variable-length, mutable run of text, with resource 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>
[4e8df745]19#include <string.h>    // e.g. strlen
[f450f2f]20
21   
22//######################### HandleNode #########################
23//private
24
25struct VbyteHeap;
26
27struct HandleNode {
28    HandleNode *flink;                                  // forward link
29    HandleNode *blink;                                  // backward link
[0f781fb8]30    VbyteHeap *ulink;                   // upward link
[f450f2f]31
32    char *s;                                            // pointer to byte string
33    unsigned int lnth;                                  // length of byte string
34}; // HandleNode
35
[0f781fb8]36VbyteHeap * DEBUG_string_heap();
[7b0e8b7]37size_t DEBUG_string_bytes_in_heap( VbyteHeap * heap );
[6cc87c0]38size_t DEBUG_string_bytes_avail_until_gc( VbyteHeap * heap );
39const char * DEBUG_string_heap_start( VbyteHeap * heap );
40
[08ed947]41void TUNING_set_string_heap_liveness_threshold( double val );
[f450f2f]42
43//######################### String #########################
44
45// A dynamically-sized string
46struct string_res {
47    HandleNode Handle; // chars, start, end, global neighbours
[804bf677]48    bool shareEditSet_owns_ulink;
[f450f2f]49    string_res * shareEditSet_prev;
50    string_res * shareEditSet_next;
51};
52
53
54//######################### charclass_res #########################
55
56struct charclass_res {
57    string_res chars;
58};
59
60void ?{}( charclass_res & ) = void;
61void ?{}( charclass_res &, charclass_res) = void;
62charclass_res ?=?( charclass_res &, charclass_res) = void;
63void ?{}( charclass_res &, const string_res & chars);
64void ?{}( charclass_res &, const char * chars );
65void ?{}( charclass_res &, const char * chars, size_t charssize );
66void ^?{}( charclass_res & );
67
68
69//######################### String #########################
70
71// Getters
72size_t size(const string_res &s);
73
74// Constructors, Assignment Operators, Destructor
75void ?{}(string_res &s); // empty string
76void ?{}(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
[4e8df745]77static inline void ?{}(string_res &s, const char* rhs) { // copy from string literal (NULL-terminated)
78    (s){ rhs, strlen(rhs) };
79}
[f450f2f]80
81void ?{}(string_res &s, const string_res & s2) = void;
82void ?{}(string_res &s, string_res & s2) = void;
83
84enum StrResInitMode { COPY_VALUE, SHARE_EDITS };
85void ?{}(string_res &s, const string_res & src, StrResInitMode, size_t start, size_t end );
86static inline void ?{}(string_res &s, const string_res & src, StrResInitMode mode ) {
87    ?{}( s, src, mode, 0, size(src));
88}
89
[1733184]90string_res & assign(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
91static inline string_res & ?=?(string_res &s, const char* other) {  // copy from string literal (NULL-terminated)
92    return assign(s, other, strlen(other));
[4e8df745]93}
[1733184]94string_res & ?=?(string_res &s, const string_res &other);
95string_res & ?=?(string_res &s, string_res &other);
96string_res & ?=?(string_res &s, char other);
[f450f2f]97
98void ^?{}(string_res &s);
99
100// IO Operator
101ofstream & ?|?(ofstream &out, const string_res &s);
102void ?|?(ofstream &out, const string_res &s);
103
104// Concatenation
[4e8df745]105void append(string_res &s, const char* buffer, size_t bsize);
[f450f2f]106void ?+=?(string_res &s, char other); // append a character
107void ?+=?(string_res &s, const string_res &s2); // append-concatenate to first string
[4e8df745]108static inline void ?+=?(string_res &s, const char* other) {
109    append( s, other, strlen(other) );
110}
[f450f2f]111
112// Character access
[218096f]113void assignAt(const string_res &s, size_t index, char val);
[f450f2f]114char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
115//char codePointAt(const string_res &s, size_t index); // revisit under Unicode
116
117// Comparisons
118bool ?==?(const string_res &s, const string_res &other);
119bool ?!=?(const string_res &s, const string_res &other);
120bool ?==?(const string_res &s, const char* other);
121bool ?!=?(const string_res &s, const char* other);
122
123// String search
124bool contains(const string_res &s, char ch); // single character
125
126int find(const string_res &s, char search);
127int find(const string_res &s, const string_res &search);
128int find(const string_res &s, const char* search);
129int find(const string_res &s, const char* search, size_t searchsize);
130
[08ed947]131int findFrom(const string_res &s, size_t fromPos, char search);
132int findFrom(const string_res &s, size_t fromPos, const string_res &search);
133int findFrom(const string_res &s, size_t fromPos, const char* search);
134int findFrom(const string_res &s, size_t fromPos, const char* search, size_t searchsize);
135
[f450f2f]136bool includes(const string_res &s, const string_res &search);
137bool includes(const string_res &s, const char* search);
138bool includes(const string_res &s, const char* search, size_t searchsize);
139
140bool startsWith(const string_res &s, const string_res &prefix);
141bool startsWith(const string_res &s, const char* prefix);
142bool startsWith(const string_res &s, const char* prefix, size_t prefixsize);
143
144bool endsWith(const string_res &s, const string_res &suffix);
145bool endsWith(const string_res &s, const char* suffix);
146bool endsWith(const string_res &s, const char* suffix, size_t suffixsize);
147
148int include(const string_res &s, const charclass_res &mask);
149int exclude(const string_res &s, const charclass_res &mask);
150
151// Modifiers
152void padStart(string_res &s, size_t n);
153void padStart(string_res &s, size_t n, char padding);
154void padEnd(string_res &s, size_t n);
155void padEnd(string_res &s, size_t n, char padding);
156
Note: See TracBrowser for help on using the repository browser.